Re: Line continuation and comments

2023-02-22 Thread Paul Bryan
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_style.html#using-backslashes-for-with-statements

On Wed, 2023-02-22 at 01:24 -0800, Edmondo Giovannozzi wrote:
> Il giorno mercoledì 22 febbraio 2023 alle 09:50:14 UTC+1 Robert
> Latest ha scritto:
> > I found myself building a complicated logical condition with many
> > ands and ors 
> > which I made more manageable by putting the various terms on
> > individual lines 
> > and breaking them with the "\" line continuation character. In this
> > context it 
> > would have been nice to be able to add comments to lines terms
> > which of course 
> > isn't possible because the backslash must be the last character on
> > the line. 
> > 
> > Question: If the Python syntax were changed to allow comments after
> > line-ending 
> > backslashes, would it break any existing code? I can't think of an
> > example.
> 
> Well you can if you use parenthesis like in:
> x = 5
> a = (x > 3 and
> # x < 21 or
>  x > 100
>  )
> You don't need the "\" to continue a line in this case
> 

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


Re: Typing Number, PyCharm

2023-02-06 Thread Paul Bryan
On Mon, 2023-02-06 at 12:11 +, Weatherby,Gerard wrote:

> On the one hand, it is a well-known type, so it should be
> recognizable to users of an API. On the other hand, Number is
> entirely abstract, so it doesn’t provide useful type checking for the
> implementation; I had to add # noinspection PyTypeChecker to 2 *
> value to keep PyCharm from complaining. Additionally, it does not
> include the Decimal type.

Hmm...

Python 3.10.9 (main, Dec 19 2022, 17:35:49) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from numbers import Number
>>> from decimal import Decimal as D
>>> isinstance(D("1.0"), Number)
True

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


Re: Improvement to imports, what is a better way ?

2023-01-18 Thread Paul Bryan
On Thu, 2023-01-19 at 09:47 +1300, dn via Python-list wrote:

> The longer an identifier, the more it 'pushes' code over to the right
> or 
> to expand over multiple screen-lines. Some thoughts on this are
> behind 
> PEP-008 philosophies, eg line-limit.

I sympathize with this issue. I've pushed the line limit to 96, which
in my case removed this pain point. My argument—though subjective—is
that we have wide screens now, and it's quite unlikely production code
will be accessed through a vintage VT-100 terminal or printed on a 80-
column dot-matrix printer. That said, even if you stick to PEP-8
proper, `black` does most of the formatting work, and it seems to do a
reasonable job despite longer module identifiers.

> In the body of the code, if every time an external identifier is used
> it 
> must be prefixed by a full 'path', the cognitive "burden" shifts from
> the aspect highlighted (above), to a reading-burden. Thus, (in
> extreme 
> cases) moving towards a 'wall of text' problem.

I tend to agree this can be a problem in some cases, but I think those
can be made manageable. For brevity's sake, I import often-used data
types directly into the module's name space. It's far more rare that I
try to abbreviate a module name; common ones like importing pandas as
pd is a good counterexample.

> In using TDD, code is constructed module-by-module (not necessarily
> a 
> Python Module). So, when it comes time to call
> avMedia.fetch_the_file() 
> [sic] there is little thinking about the "avMedia" bit. The emphasis
> is 
> on the function-name, and it's parameters. 'I need that file so that
> I 
> can ...'.

I'm not entirely sure what you mean by not a Python module. Even in
test modules, I would only import what's required. If it turns out
`fetch_the_file` is called dozens of times or more, I would have no
qualm about importing it directly into the test module's namespace so
that it doesn't need to be prefixed at all.

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


Re: Improvement to imports, what is a better way ?

2023-01-18 Thread Paul Bryan
I would suggest allowing each module to define its own imports, don't
import what a module doesn't consume, keep them simple, avoid devising
a common namespace for each, and let tools like isort/black work out
how to order/express them in source files.

On Wed, 2023-01-18 at 10:43 -0800, Dan Kolis wrote:
> This program has lots of files and each is well segregated for a
> concept.
> 
> the top of each as a heap of imports, all identical. Well the very
> top has some one of's
> 
> import os as    os
> import sys as   sys
> import importlib as importlib
> import datetime as  dt
> from   tokenize import  maybe
> import signal
> 
> from   tkinter import filedialog as fd
> from   tkinter.messagebox import    showinfo
> import tkinter as   tk  
> from   tkinter import   ttk
> from   tkinter import   font
>  
> from   PIL import Image as  pl
> from   PIL import ImageTk   as  ii
> 
> # Imports part of this program 
> import aboutTime as tt  # Time dates timestamps and the
> like
> import avMedia as   av  # Audio and maybe video 'someday'
> well definitely lots of TTS text to speech
> import basicSwitchboard as  sc  # First switchboard lurking.
> Kickoff to sequence viewers
> import bestNotifications as bn  # Alerts, modals and
> notifications of many kinds including TK windows
> import bitBlitting as   bb  # Help - # A setup window with
> basic facts written into files and the workspace
> import configSetting as cs  # A setup window with basic facts
> written into files and the workspace
> import devPeeks as  dp  # Developments peek assets code
> for adding features and debugging
> import fileIo as    io  # File reads, writes even some of
> the the pickle and unpickling
> import forFun as    ff  # Staging area for uncertian
> features, also some dynamic code inclusion
> import fractionScreens as   fs  # Common window pieces for TK
> windows in sequence viewers
> import genomeDb as  gd  # IO to from databases external
> files gbk and others sure
> import globalIdeas as   gi  # Common code for stuff used
> everywhere and definition of share DOT OBJECTS
> import insertableEditors as ie  # Text editor(s) and support for
> that, some language issues managed too
> import modalSimple as   mo  # Modal windows icp seq ssues,
> not used much currently
> import osDependant as   od  # Operating system dependant
> calls and adaptions
> import pickle as    pk  # Packaging to and from file
> system for objects especially DOT OBJECTS
> import screenBuilder1 as    sb  # Screen maker for TKinter and
> TKinter ++ windows
> import selectViewer as  sv  # Window for picking which
> sequence viewers are enabled
> import sequencesMaintain as sm  # Touching up temporal version
> issues of DOT OBJECTS
> import sequencesOverview as so  # Working with sequences as macro
> facts, lists, see turn off etc
> import serverHttp1 as   sh1 # Servers for HTTP - User Support
> import serverHttp2 as   sh2 # Servers for HTTP - Protein
> viewing
> import specialFour as   sf  # Classes and stuff for viewer
> four, a very complex viewer
> import stagingNow as    sn  # More stabler new ideas getting
> tried out and moved in
> import taskingFunction as   tf  # Tasker for real timeish event
> processor calls. Has two versions both work
> import toastMaker as    tm  # Notifications
> import transFormations as   xf  # Sequence transFormations from
> mother natures ideas like DNA and RNA
> import unlovedMenus as  um  # Pretty rarely used ond
> fashioned menus. A while interface is in here that works
> import wayOffline as    wo  # Code not discarded but just
> studies, etc
> import windowsX as  wx  # Windows Life ! X11 esp TK not
> MS Windoze ...
> 
> So the file for instance fileIo.py has a duplicate of this.
> 
> I want to be able to call any code by using the two char prefix form
> anywhere. ex: io.get_Sequence(  'abc.fa' )
> 
> this seems weirdly disorderly. when it starts it sort of iterates
> down into objects, backs up etc.
> 
> What's the right way to do this ?
> 
> Thank you
> Dan

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


Re: set.add() doesn't replace equal element

2022-12-30 Thread Paul Bryan
It seems to me like you have to ideas of what "equal" means. You want 
to update a "non-equal/equal" value in the set (because of a different 
time stamp). If you truly considered them equal, the time stamp would 
be irrelevant and updating the value in the set would be unnecessary.


I would:

a) /not/ consider two different leases with two different time stamps 
to be equal, and
b) as already mentioned, store them in another data structure like a 
dictionary.


Not knowing the specifics of the DHCP object structure, if a DHCP lease 
object has some immutable key or other durable immutable attribute, I 
would be inclined to make that the dictionary key, and store the DHCP 
object as the value.



On Fri, Dec 30 2022 at 04:27:56 PM -0600, Ian Pilcher 
 wrote:

On 12/30/22 15:47, Paul Bryan wrote:
What kind of elements are being added to the set? Can you show 
reproducible sample code?


The objects in question are DHCP leases.  I consider them "equal" if
the lease address (or IPv6 prefix) is equal, even if the timestamps 
have

changed.  That code is not small, but it's easy to demonstrate the
behavior.

>>> import datetime
>>> class Foo(object):
... def __init__(self, index):
... self.index = index
... self.timestamp = datetime.datetime.now()
... def __eq__(self, other):
... return type(other) is Foo and other.index == self.index
... def __hash__(self):
... return hash(self.index)
... def __repr__(self):
... return f'Foo({self.index}) created at 
{str(self.timestamp)}'

...
>>> f1 = Foo(1)
>>> s = { f1 }
>>> s
{Foo(1) created at 2022-12-30 16:24:12.352908}
>>> f2 = Foo(1)
>>> f2
Foo(1) created at 2022-12-30 16:24:35.489208
>>> s.add(f2)
>>> s
{Foo(1) created at 2022-12-30 16:24:12.352908}

--

Google  Where SkyNet meets 
Idiocracy





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


Re: set.add() doesn't replace equal element

2022-12-30 Thread Paul Bryan
What kind of elements are being added to the set? Can you show 
reproducible sample code?


On Fri, Dec 30 2022 at 03:41:19 PM -0600, Ian Pilcher 
 wrote:
I just discovered this behavior, which is problematic for my 
particular

use.  Is there a different set API (or operator) that can be used to
add an element to a set, and replace any equal element?

If not, am I correct that I should call set.discard() before calling
set.add() to achieve the behavior that I want?

--

Google  Where SkyNet meets 
Idiocracy


--



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


Re: Are these good ideas?

2022-11-14 Thread Paul Bryan
Seems like this is a use case for context managers and/or context
variables:

https://docs.python.org/3/library/contextlib.html
https://docs.python.org/3/library/contextvars.html


On Mon, 2022-11-14 at 17:14 +, Stephen Tucker wrote:
> Hi,
> 
> I have two related issues I'd like comments on.
> 
> Issue 1 - Global Values
> 
> Some years ago, I had a situation where
> (a) I could supply low-level functions that carry out tasks,
> (b) I needed those functions to communicate with each other, but
> (c) I had no access to the module that invoked my functions.
> 
> In order to achieve this, I hit on the idea that I also supply a
> module
> that I describe as a "global values" module. This module …
> (i) … defines the values that the functions use to communicate with
> each
> other;
> (ii) … is the subject of an import statement in each of my functions;
> (iii) … initialises its values at the start of each run (since the
> import
> only carries out an actual import once per session);
> (iv) … acts as a repository for the values thereafter.
> 
> This solution works well.
> 
> Given that I am not particularly concerned about efficiency,
> (1) Is this a reasonable way to achieve this goal?
> (2) Do you know of any better ways?
> 
> Issue 2 - Passed Parameters
> 
> I am now facing another situation where I am wanting to pass 6 or 7
> parameters down through several layers of logic (function A calling
> function B calling ... ) and for results to be passed back.
> 
> Having had the idea described above, I am considering using it again
> to
> save all the parameter-and-results passing.
> 
> I see nothing wrong with doing that, but I may well be missing
> something!
> 
> Comments, please!
> 
> Stephen Tucker.

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


Re: python 3.10 vs breakage

2022-08-26 Thread Paul Bryan
The pronterface README doc [1] recommends Python 3.6, so I'd say that
it's likely incompatible with changes in Python 3.10. I think your best
option would be to either downgrade to their recommended version of
Python, or file an issue in their GitHub repository to address the
incompatibility. 

[1] https://github.com/kliment/Printrun/blob/master/README.md

On Fri, 2022-08-26 at 17:36 -0400, gene heskett wrote:
> On 8/26/22 16:54, Paul Bryan wrote:
> > Why can't you build linuxcnc with it? Why has Octoprint quit
> > talking to
> > 3d printers? Why won't pronterface buy it? Why can't you find a
> > 4.0.7
> > version of wxPython? Why is it sitting there staring at you? What
> > is
> > bookworm? What is bullseye?
> 
> Bullseye is the current debian-11, buster is last years, bookworm is
> next.
> 
> Linuxcnc builds just fine on armhf buster, with its python-3.9.4.
> fails 
> from 3.10 in bullseye. Pronterface.py can't find wxPython 4.0 or 
> greater, with 4.0.7 installed. Octoprint did work, but has now
> stopped. 
> So my 3d printing has become a sneakernet exercise again. Adding 3 to
> 5 
> more steps between OpenCSAD and the printer that will make my
> designs. 
> The error code file from this mornings attempt to run pronterface.py
> is at
> 
> <http://geneslinuxbox.net:6309/armhf>
> 
> Is there a workaround?
> 
> Thank you.
> > On Fri, 2022-08-26 at 16:37 -0400, gene heskett wrote:
> > > Greetings all;
> > > 
> > > Its now become obvious that 3.10 has broken some things. I can't
> > > build
> > > linuxcnc with it. And
> > > Octoprint has quit talking to 3d printers, now pronterface won't
> > > buy
> > > it,
> > > can't find a 4.0.7
> > > version of wxPython with it sitting there staring at us.
> > > 
> > > Whats chances of a fixed version for bookworm? Or even a bugs
> > > fixed
> > > release for bullseye?
> > > 
> > > Thanks all.
> > > 
> > > Cheers, Gene Heskett.
> > > -- 
> > > "There are four boxes to be used in defense of liberty:
> > >    soap, ballot, jury, and ammo. Please use in that order."
> > > -Ed Howdershelt (Author, 1940)
> > > If we desire respect for the law, we must first make the law
> > > respectable.
> > >    - Louis D. Brandeis
> > > Genes Web page <http://geneslinuxbox.net:6309/>
> > > 
> > 
> 
> 
> Cheers, Gene Heskett.

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


Re: python 3.10 vs breakage

2022-08-26 Thread Paul Bryan
Why can't you build linuxcnc with it? Why has Octoprint quit talking to
3d printers? Why won't pronterface buy it? Why can't you find a 4.0.7
version of wxPython? Why is it sitting there staring at you? What is
bookworm? What is bullseye?

On Fri, 2022-08-26 at 16:37 -0400, gene heskett wrote:
> Greetings all;
> 
> Its now become obvious that 3.10 has broken some things. I can't
> build 
> linuxcnc with it. And
> Octoprint has quit talking to 3d printers, now pronterface won't buy
> it, 
> can't find a 4.0.7
> version of wxPython with it sitting there staring at us.
> 
> Whats chances of a fixed version for bookworm? Or even a bugs fixed 
> release for bullseye?
> 
> Thanks all.
> 
> Cheers, Gene Heskett.
> -- 
> "There are four boxes to be used in defense of liberty:
>   soap, ballot, jury, and ammo. Please use in that order."
> -Ed Howdershelt (Author, 1940)
> If we desire respect for the law, we must first make the law
> respectable.
>   - Louis D. Brandeis
> Genes Web page 
> 

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


Re: subprocess.popen how wait complete open process

2022-08-21 Thread Paul Bryan
Sometimes, launching subprocesses can seem like punishment. I don't
think there is a standard cross-platform way to know when a launched
asynchronous process is "fully open" (i.e. fully initialized, accepting
user input).

On Sun, 2022-08-21 at 02:11 -0700, simone zambonardi wrote:
> Hi, I am running a program with the punishment subrocess.Popen(...)
> what I should do is to stop the script until the launched program is
> fully open. How can I do this? I used a time.sleep() function but I
> think there are other ways. Thanks

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


Re: Information about Dying kernel

2022-08-07 Thread Paul Bryan
Have you tried turning it off and back on again?

On Sun, 2022-08-07 at 18:59 +0200, nhlanhlah198506 wrote:
> Greetings What can I do if my computer said my kernels has died Thank
> you Sent from my Galaxy

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


Re: Which linux distro is more conducive for learning the Python programming language?

2022-08-03 Thread Paul Bryan
I wouldn't say any particular Linux distribution is appreciably better
for Python development than another. I would suggest using a version of
a Linux distribution that supports a recent Python release (e.g. 3.9 or
3.10).

On Thu, 2022-08-04 at 10:22 +0800, Turritopsis Dohrnii Teo En Ming
wrote:
> Subject: Which linux distro is more conducive for learning the Python
> programming language?
> 
> Good day from Singapore,
> 
> May I know which linux distro is more conducive for learning the
> Python programming language?
> 
> Since I have absolutely and totally FREE RHEL developer subscription
> (I don't need to spend a single cent), can I use Red Hat Enterprise
> Linux version 9.0 to learn Python?
> 
> Is it the most popular linux distro for learning Python?
> 
> I just want to know which linux distro and version is more conducive
> for learning Python. Because there are thousands of linux distros out
> there. And I just want to settle down on a particular linux distro
> and
> version.
> 
> Thank you.
> 
> Regards,
> 
> Mr. Turritopsis Dohrnii Teo En Ming
> Targeted Individual in Singapore
> 4 Aug 2022 Thursday
> Blogs:
> https://tdtemcerts.blogspot.com
> https://tdtemcerts.wordpress.com

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


Re: Subtract n months from datetime

2022-06-20 Thread Paul Bryan
Here's how my code does it:


import calendar

def add_months(value: date, n: int):
  """Return a date value with n months added (or subtracted if
negative)."""
  year = value.year + (value.month - 1 + n) // 12
  month = (value.month - 1 + n) % 12 + 1
  day = min(value.day, calendar.monthrange(year, month)[1])
  return date(year, month, day)

Paul

On Tue, 2022-06-21 at 05:29 +0100, Paulo da Silva wrote:
> Hi!
> 
> I implemented a part of a script to subtract n months from datetime.
> Basically I subtracted n%12 from year and n//12 from the month adding
> 12 
> months when it goes<=0. Then used try when converting to datetime
> again. 
> So, if the day is for example 31 for a 30 days month it raises a 
> ValuError exception. Then I subtract 1 to day and repeat.
> 
> The code seems too naive and very very complicated!
> What is the best way to achieve this? Any existent module?
> 
> At the very end, what I want is to subtract nx where x can be y, m,
> w, d 
> for respectively years, months, weeks or days.
> 
> I feel I am missing something here ...
> 
> Thanks.
> Paulo
> 

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


Re: F-string usage in a print()

2022-05-24 Thread Paul Bryan
Try something like:

print(f"Year = {years}, Future value = {future_value}")

On Tue, 2022-05-24 at 21:14 +, Kevin M. Wilson via Python-list
wrote:
> future_value = 0
> for i in range(years):
> # for i in range(months):
>    future_value += monthly_investment
>    future_value = round(future_value, 2)
>    # monthly_interest_amount = future_value * monthly_interest_rate
>    # future_value += monthly_interest_amount
>    # display the result
>    print(f"Year = ", years + f"Future value = \n", future_value)When
> joining a string with a number, use an f-string otherwise, code a
> str() because a implicit convert of an int to str causes a
> TypeError!Well...WTF! Am I not using the f-string function
> correctly...in the above line of code???
> Caddy Man
> 
> Good sense makes one slow to anger, and it is his glory tooverlook an
> offense.
> 
> Proverbs 19:11
> 

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


Re: Non-deterministic set ordering

2022-05-15 Thread Paul Bryan
This may explain it:
https://stackoverflow.com/questions/27522626/hash-function-in-python-3-3-returns-different-results-between-sessions

On Mon, 2022-05-16 at 04:20 +0100, Rob Cliffe via Python-list wrote:
> 
> 
> On 16/05/2022 04:13, Dan Stromberg wrote:
> > 
> > On Sun, May 15, 2022 at 8:01 PM Rob Cliffe via Python-list 
> >  wrote:
> > 
> >     I was shocked to discover that when repeatedly running the
> > following
> >     program (condensed from a "real" program) under Python 3.8.3
> > 
> >     for p in { ('x','y'), ('y','x') }:
> >      print(p)
> > 
> >     the output was sometimes
> > 
> >     ('y', 'x')
> >     ('x', 'y')
> > 
> >     and sometimes
> > 
> >     ('x', 'y')
> >     ('y', 'x')
> > 
> >     Can anyone explain why running identical code should result in
> >     traversing a set in a different order?
> > 
> > 
> > Sets are defined as unordered so that they can be hashed internally
> > to 
> > give O(1) operations for many tasks.
> > 
> > It wouldn't be unreasonable for sets to use a fixed-by-arbitrary 
> > ordering for a given group of set operations, but being
> > unpredictable 
> > deters developers from mistakenly assuming they are ordered.
> > 
> > If you need order, you should use a tuple, list, or something like 
> > https://grantjenks.com/docs/sortedcontainers/sortedset.html
> Thanks, I can work round this behaviour.
> But I'm curious: where does the variability come from?  Is it
> deliberate 
> (as your answer seems to imply)?  AFAIK the same code within the
> *same 
> run* of a program does produce identical results.
> Best wishes
> Rob Cliffe

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


Re: .0 in name

2022-05-13 Thread Paul Bryan
On Fri, 2022-05-13 at 22:02 +, Avi Gross via Python-list wrote:

> So why you wonder where it is documented that variables cannot be
> what you feel like is a bit puzzling! 

I had just assumed on good faith that the request to the documentation
would be so that the OP could determine what is valid identifier
syntax.

Paul


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


Re: .0 in name

2022-05-13 Thread Paul Bryan
On Sat, 2022-05-14 at 00:47 +0800, bryangan41 wrote:

> May I know (1) why can the name start with a number?

The name of an attribute must be an identifier. An identifier cannot
begin with a decimal number.

> (2) where in the doc is it?!

https://docs.python.org/3/reference/lexical_analysis.html#identifiers

Paul

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


Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

2022-04-14 Thread Paul Bryan
I think because minutes and hours can easily be composed by multiplying
seconds. days is separate because you cannot compose days from seconds;
leap seconds are applied to days at various times, due to
irregularities in the Earth's rotation.

On Thu, 2022-04-14 at 15:38 +0200, Loris Bennett wrote:
> "Loris Bennett"  writes:
> 
> > Hi,
> > 
> > With Python 3.9.2 I get
> > 
> >   $ import datetime
> >   $ s = "1-00:01:01"
> >   $ t = datetime.datetime.strptime(s, "%d-%H:%M:%S")
> >   $ d = datetime.timedelta(days=t.day, hours=t.hour,
> > minutes=t.minute, seconds=t.second)
> >   $ d.days
> >   1
> >   $ d.seconds
> >   61
> >   $ d.minutes
> >   AttributeError: 'datetime.timedelta' object has no attribute
> > 'minutes'
> > 
> > Is there a particular reason why there are no attributes 'minutes'
> > and
> > 'hours and the attribute 'seconds' encompasses is the entire
> > fractional
> > day?
> 
> That should read:
> 
>   Is there a particular reason why there are no attributes 'minutes'
> and
>   'hours' and the attribute 'seconds' encompasses the entire
> fractional
>   day?
> 
> > Cheers,
> > 
> > Loris
> -- 
> Dr. Loris Bennett (Herr/Mr)
> ZEDAT, Freie Universität Berlin Email
> loris.benn...@fu-berlin.de

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


Re: for convenience

2022-03-21 Thread Paul Bryan
No, nor did I suggest that you did. `context` is presumably an
attribute in the `bpy` module, for which you are creating a `context`
attribute in your module.

On Mon, 2022-03-21 at 22:31 +0100, Paul St George wrote:
> Hi,
> I do not (knowingly) have a module called ‘context'.
> 
> 
> 
> 
> > On 21 Mar 2022, at 22:24, Paul Bryan  wrote:
> > 
> > Assuming `bpy` is a module, you're creating a new attribute in your
> > module, `context`, that contains a reference to the same object
> > that is referenced in the `context` attribute in the `bpy` module.
> > 
> > On Mon, 2022-03-21 at 22:12 +0100, Paul St George wrote:
> > > 
> > > When I am writing code, I often do things like this:
> > > 
> > > context = bpy.context  # convenience
> > > 
> > > then whenever I need bpy.context, I only need to write context
> > > 
> > > 
> > > Here’s my question:
> > > 
> > > When I forget to use the convenient shorter form 
> > > 
> > > why is bpy.context not interpreted as bpy.bpy.context?
> > > 
> > > 
> > > —
> > > Paul St George
> > > 
> > > 
> > > 
> > > 
> > > 
> > 
> > 
> 

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


Re: for convenience

2022-03-21 Thread Paul Bryan
Assuming `bpy` is a module, you're creating a new attribute in your
module, `context`, that contains a reference to the same object that is
referenced in the `context` attribute in the `bpy` module.

On Mon, 2022-03-21 at 22:12 +0100, Paul St George wrote:
> 
> When I am writing code, I often do things like this:
> 
> context = bpy.context  # convenience
> 
> then whenever I need bpy.context, I only need to write context
> 
> 
> Here’s my question:
> 
> When I forget to use the convenient shorter form 
> 
> why is bpy.context not interpreted as bpy.bpy.context?
> 
> 
> —
> Paul St George
> 
> 
> 
> 
> 

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


Re: A Newspaper for Python Mailing Lists

2022-01-11 Thread Paul Bryan
Subscribed. ️

On Wed, 2022-01-12 at 00:35 +0400, Abdur-Rahmaan Janhangeer wrote:
> Added RSS:
> 
> 2.0 unless later versions have some advantages:
> 
> https://pyherald.com/rss.xml
> 
> Kind Regards,
> 
> Abdur-Rahmaan Janhangeer
> about | blog 
> github
> Mauritius
> 

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


Re: A Newspaper for Python Mailing Lists

2022-01-08 Thread Paul Bryan
+1 to RSS.

On Sun, 2022-01-09 at 10:28 +0400, Abdur-Rahmaan Janhangeer wrote:
> Well yes XD though LWN covers Py topics well when it wants
> 
> 
> 1. Yes sure, did not expect RSS interest
> 2. Excuse my blunder, will do!
> 
> On Sun, 9 Jan 2022, 01:15 Peter J. Holzer,  wrote:
> 
> > On 2021-12-26 20:40:03 +0400, Abdur-Rahmaan Janhangeer wrote:
> > > I have started a newspaper (not newsletter) focused
> > > on interesting reads on Python mailing lists. Don't tag
> > > on the fact that holiday seasons are the worst times for
> > > launch according to marketing folks, I started this to note
> > > down interesting mails. This might also be a great way to
> > > bring mailing list gems to a wider readership. So, here's
> > > the url https://pyherald.com/
> > 
> > Something like [LWN](https://lwn.net/) for Python? Neat.
> > 
> > Two suggestions:
> > 
> > 1. Could you add an RSS or Atom feed?
> > 
> > 2. CSS «word-break: break-all» seems like a really weird choice for
> >    English language text. If you really want to break words across
> >    lines, use «hyphens: auto».
> > 
> >     hp
> > 
> > --
> >    _  | Peter J. Holzer    | Story must make more sense than
> > reality.
> > > _|_) |    |
> > > >   | h...@hjp.at |    -- Charles Stross, "Creative
> > > > writing
> > __/   | http://www.hjp.at/ |   challenge!"
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> > 

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


Re: Custom designed alarm clock

2021-12-18 Thread Paul Bryan
Suggested reading:

https://pypi.org/project/python-for-android/
https://play.google.com/store/apps/details?id=org.qpython.qpy3
https://www.androidauthority.com/an-introduction-to-python-on-android-759685/
https://data-flair.training/blogs/android-app-using-python/

On Sat, 2021-12-18 at 18:36 -0500, Steve wrote:
> 
> I have designed a simple alarm using Python. It has about 10 limes.
> How do I convert it to an app that I can on my android Moto E power
> 2021
> phone?
> 
> Steve
> 

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


[issue46060] Clarify asyncio.new_event_loop return value

2021-12-13 Thread Paul Bryan


Change by Paul Bryan :


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

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



[issue46060] Clarify asyncio.new_event_loop return value

2021-12-12 Thread Paul Bryan


Change by Paul Bryan :


--
keywords: +patch
nosy: +pbryan
nosy_count: 2.0 -> 3.0
pull_requests: +28299
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/30078

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



[issue46060] Clarify asyncio.new_event_loop return value

2021-12-12 Thread Paul Bryan


New submission from Paul Bryan :

Currently, the documentation states it creates a new event loop; it should also 
indicate that it returns the newly created event loop.

--
assignee: docs@python
components: Documentation
messages: 408425
nosy: docs@python, pbryan2
priority: normal
severity: normal
status: open
title: Clarify asyncio.new_event_loop return value
versions: Python 3.10, Python 3.11

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



Re: Isn't TypeError built in?

2021-12-12 Thread Paul Bryan
Yes, TypeError is built in. The only thing I can think of is that
something has deleted `TypeError` from `__builtins__`? It would be
interesting to see what's in `__builtins__` when `__del__` is called.

On Mon, 2021-12-13 at 12:22 +1100, Mike Dewhirst via Python-list wrote:
> Obviously something is wrong elsewhere but I'm not sure where to
> look. 
> Ubuntu 20.04 with plenty of RAM.
> 
>  def __del__(self):
>  try:
>  for context_obj in self._context_refs:
>  try:
>  delattr(context_obj, self._attr_name)
>  except AttributeError:
>  pass
> 
>  except TypeError:        # THIS IS LINE 96 IN THE APACHE2
> ERROR 
> LOG BELOW
> 
>  # WeakSet.__iter__ can crash when interpreter is
> shutting 
> down due
>  # to _IterationGuard being None.
>  pass
> 
> [Mon Dec 13 01:15:49.875993 2021] [mpm_event:notice] [pid 1033:tid 
> 140446449658944] AH00493: SIGUSR1 received.  Doing graceful restart
> [Mon Dec 13 01:15:49.878443 2021] [so:warn] [pid 1033] AH01574:
> module 
> dav_module is already loaded, skipping
> [Mon Dec 13 01:15:49.885659 2021] [mpm_event:notice] [pid 1033:tid 
> 140446449658944] AH00489: Apache/2.4.41 (Ubuntu) SVN/1.13.0 
> OpenSSL/1.1.1f mod_wsgi/4.6.8 Python/3.8 configured -- resuming
> normal 
> operations
> [Mon Dec 13 01:15:49.885664 2021] [core:notice] [pid 1033:tid 
> 140446449658944] AH00094: Command line: '/usr/sbin/apache2'
> Exception ignored in: 
> Traceback (most recent call last):
>    File "/usr/local/lib/python3.8/dist-packages/asgiref/local.py",
> line 
> 96, in __del__
> NameError: name 'TypeError' is not defined
> Exception ignored in: 
> Traceback (most recent call last):
>    File "/usr/local/lib/python3.8/dist-packages/asgiref/local.py",
> line 
> 96, in __del__
> NameError: name 'TypeError' is not defined
> 
> Any hints welcome ...
> 
> Thanks
> 
> Mike
> 
> -- 
> Signed email is an absolute defence against phishing. This email has
> been signed with my private key. If you import my public key you can
> automatically decrypt my signature and be sure it came from me. Just
> ask and I'll send it to you. Your email software can handle signing.
> 

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


Re: Urllib.request vs. Requests.get

2021-12-07 Thread Paul Bryan
Cloudflare, for whatever reason, appears to be rejecting the `User-
Agent` header that urllib is providing:`Python-urllib/3.9`. Using a
different `User-Agent` seems to get around the issue:

import urllib.request

req = urllib.request.Request(
url="https://juno.sh/direct-connection-to-jupyter-server/;,
method="GET",
headers={"User-Agent": "Workaround/1.0"},
)

res = urllib.request.urlopen(req)

Paul

On Tue, 2021-12-07 at 12:35 +0100, Julius Hamilton wrote:
> Hey,
> 
> I am currently working on a simple program which scrapes text from
> webpages
> via a URL, then segments it (with Spacy).
> 
> I’m trying to refine my program to use just the right tools for the
> job,
> for each of the steps.
> 
> Requests.get works great, but I’ve seen people use
> urllib.request.urlopen()
> in some examples. It appealed to me because it seemed lower level
> than
> requests.get, so it just makes the program feel leaner and purer and
> more
> direct.
> 
> However, requests.get works fine on this url:
> 
> https://juno.sh/direct-connection-to-jupyter-server/
> 
> But urllib returns a “403 forbidden”.
> 
> Could anyone please comment on what the fundamental differences are
> between
> urllib vs. requests, why this would happen, and if urllib has any
> option to
> prevent this and get the page source?
> 
> Thanks,
> Julius

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


Re: Advantages of Default Factory in Dataclasses

2021-11-21 Thread Paul Bryan
On Sun, 2021-11-21 at 21:51 +0400, Abdur-Rahmaan Janhangeer wrote:
> 
> On Tue, Nov 16, 2021 at 7:17 PM Paul Bryan  wrote:
> > On Tue, 2021-11-16 at 17:04 +0400, Abdur-Rahmaan Janhangeer wrote:
> > 
> > > A simple question: why do we need field(default_factory ) in
> > > dataclasses?
> > 
> > 
> > To initialize a default value when a new instance of the dataclass
> > is created. For example, if you want a field to default to a dict.
> > A new dict is created for each instance of the dataclass created.
> > 
> 
> 
> Why not have an attribute which returns a deep copy of a dict?

You can certainly write a default factory to return a deep copy. I'm
not understanding your question about the attribute though. Attribute
in what object? What might the code look like using an attribute?

> Like the only advantage of default factory is copying whatever we
> specify? 

The advantage of the default factory is that it can generate a value at
the time a data class is initialized.

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


Re: Advantages of Default Factory in Dataclasses

2021-11-16 Thread Paul Bryan
On Tue, 2021-11-16 at 17:04 +0400, Abdur-Rahmaan Janhangeer wrote:

> A simple question: why do we need field(default_factory ) in
> dataclasses?

To initialize a default value when a new instance of the dataclass is
created. For example, if you want a field to default to a dict. A new
dict is created for each instance of the dataclass created.

> Why not make that field as an attribute return a function?

I do not understand the question.

> Useful implementation examples / use cases appreciated.

Any case where a you want a dataclass field to default to a mutable
value. Examples: dicts, lists, other dataclasses.

Paul

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


Re: Python script seems to stop running when handling very large dataset

2021-10-29 Thread Paul Bryan
With so little information provided, not much light will be shed. When
it stops running, are there any errors? How is the dataset being
processed? How large is the dataset? How large a dataset can be
successfully processed? What libraries are being used? What version of
Python are you using? On what operating system? With how much memory?
With how much disk space is used? How much is free? Are you processing
files or using a database? If the latter, what database? Does it write
intermediate files during processing? Can you monitor memory usage
during processing (e.g. with a system monitor) to see how much memory
is consumed?


On Fri, 2021-10-29 at 23:42 +0100, Shaozhong SHI wrote:
> Python script works well, but seems to stop running at a certain
> point when
> handling very large dataset.
> 
> Can anyone shed light on this?
> 
> Regards, David

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


Re: Request for argmax(list) and argmin(list)

2021-09-01 Thread Paul Bryan
Why not:

>>> l = [1, 3, 5, 9, 2, 7]
>>> l.index(max(l))
3
>>> l.index(min(l))
0

On Tue, 2021-08-31 at 21:25 -0700, ABCCDE921 wrote:
> I dont want to import numpy
> 
> argmax(list) 
>    returns index of (left most) max element
> 
>  argmin(list)
>    returns index of (left most) min element

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


Re: src layout for projects seems not so popular

2021-08-31 Thread Paul Bryan
An interesting thread in PyPA (with links to other threads) discussing
src layout:
https://github.com/pypa/packaging.python.org/issues/320

On Tue, 2021-08-31 at 10:53 +0400, Abdur-Rahmaan Janhangeer wrote:
> Greetings list,
> 
> Just an observation. Out of Github's trending repos for
> Python for today, I could find only 2 repos using the src layout.
> Matplotlib and another one.
> https://github.com/trending/python?since=daily
> 
> Kind Regards,
> 
> Abdur-Rahmaan Janhangeer
> about  | blog
> 
> github 
> Mauritius

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


Re: a simple question

2021-07-26 Thread Paul Bryan
It would help to know the error message you get every time.

On Mon, 2021-07-26 at 22:19 +, Glenn Wilson via Python-list wrote:
> I recently downloaded the latest version of python, 3.9.6. Everything
> works except, the turtle module. I get an error message every time ,
> I use basic commands like forward, backward, right and left. My
> syntax is correct: pat.forward(100) is an example. Can you tell me
> what is wrong.
>      thanks, glenn

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


Re: Where to keep local Python modules?

2021-07-23 Thread Paul Bryan
On my Arch Linux box, slightly different path, but still in .local/bin:

pbryan@dynamo:~$ python3
Python 3.9.6 (default, Jun 30 2021, 10:22:16) 
[GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/lib/python39.zip', '/usr/lib/python3.9', 
'/usr/lib/python3.9/lib-dynload', 
'/home/pbryan/.local/lib/python3.9/site-packages', 
'/usr/lib/python3.9/site-packages']
>>> 


On Fri, 2021-07-23 at 22:46 +0300, Roland Mueller via Python-list
wrote:
> Hello,
> 
> pe 23. heinäk. 2021 klo 21.44 Chris Green (c...@isbd.net) kirjoitti:
> 
> > This isn't a question about how to set PYTHONPATH so that Python
> > code
> > can find imported modules, it's about what is a sensible layout for
> > one's home directory - i.e. where to put Python modules.
> > 
> > I'm running Linux and have a number of Python modules that are only
> > used by my own code.  My top level Python code is all in ~/bin. 
> > I'd
> > prefer to separate the modules so that they don't clutter the name
> > space.
> > 
> > Currently I have my Python modules in a subdirectory of ~/bin and
> > my
> > Python path is set as:-
> > 
> >     PYTHONPATH=/home/chris/bin/pymods
> > 
> > Is this a reasonable approach?  Is there a 'standard' name for the
> > directory containing modules, or a standard place for it?  (I don't
> > mean a system-wide standard place, I mean a 'my' standard place).
> > 
> > Under recent Linux distros there is $HOME/.local/ containing bin
> > and lib
> directories. May be it's ok to use this for user-specific python
> settings
> under Linux.
> 
> E.g. in .bashrc
> export PYTHONPATH=$HOME/.local/python
> 
> Result can be checked then in Python:
> python
> > > > import sys
> > > > sys.path
> ['', '/home/someuser/.local/lib/python', '/usr/lib64/python39.zip',
> '/usr/lib64/python3.9', '/usr/lib64/python3.9/lib-dynload',
> '/usr/local/lib/python3.9/site-packages',
> '/usr/lib64/python3.9/site-packages', '/usr/lib/python3.9/site-
> packages']
> 
> BR,
> Roland
> 
> 
> 
> 
> > 
> > --
> > Chris Green
> > ·
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> > 

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


Re: Replacement for Mailman

2021-06-08 Thread Paul Bryan
How about Mailman 3.x on Python 3.x?

On Tue, 2021-06-08 at 15:08 -0400, D'Arcy Cain wrote:
> Given that mailman still runs under 2.7 and that's being deprecated,
> does
> anyone have a suggestion for a replacement?
> 

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


Re: Proposal: Disconnect comp.lang.python from python-list

2021-05-06 Thread Paul Bryan
I do not believe my proposal has reached—or will reach—consensus. It
seems there are some who still value the linkage between the two, and
the S/N ratio is indeed low enough it doesn't warrant changing from the
status quo. Thanks everyone for the consideration and discussion. 

Paul

On Thu, 2021-05-06 at 18:49 +0100, Stestagg wrote:
> Where's this discussion going?
> 
> Let's not get too caught up on definitions or the sizes of everyone's
> respective .. newsgroups.
> 
> Which of the practically possible options are best for this list <->
> newsgroup setup?
> 
> Thanks
> 
> Steve
> 
> On Thu, May 6, 2021 at 6:47 PM Jon Ribbens via Python-list <
> python-list@python.org> wrote:
> 
> > On 2021-05-06, Richard Damon  wrote:
> > > On 5/6/21 9:44 AM, Jon Ribbens via Python-list wrote:
> > > > Sounds like nearly all moderated lists/forums then.
> > > 
> > > Then perhaps you have never been on a real Moderated mailing list
> > > or
> > > Forum.
> > 
> > Ah, the "no true scotsforum" argument ;-)
> > 
> > > > > While you could setup a robo-moderator to do a similar thing,
> > > > > Usenet
> > > > > posters will not have 'pre-subscribed' before posting, and
> > > > > the From
> > > > > address is no where near as relaible as invalid From
> > > > > addresses ARE
> > > > > allowed, and since the message comes via a NNTP injection
> > > > > source relay,
> > > > > non-verifiable. This make the job a LOT harder.
> > > > It makes essentially no difference at all.
> > > It sure does. Have you every actually TRIED to run a moderated
> > > Usenet
> > > group, or know anyone who has, especially a somewhat busy group?
> > 
> > As I already mentioned, I am a moderator of a Usenet group.
> > 
> > > I am presuming that the current gateway isn't bringing all the
> > > messages
> > > from Usenet into the mailing list. This is obvious as we don't
> > > see the
> > > noise here. The Cabal that runs the 'Big-8' doesn't really care
> > > what
> > > sort of filters are added at such a gateway.
> > > 
> > > To setup a moderated group that defines similar filters in place
> > > for
> > > messages getting to Usenet, particularly for a group intended to
> > > replace
> > > a 'reasonably' working unmoderated group, is likely not going to
> > > be
> > > viewed well.
> > 
> > Have you every actually TRIED to run a moderated Usenet group, or
> > know
> > anyone who has, especially a somewhat busy group? Of *course*
> > moderated
> > groups put filters on what they receive, what do you think group
> > moderation is *for* if not to block things?
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> > 

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


Re: Proposal: Disconnect comp.lang.python from python-list

2021-05-06 Thread Paul Bryan
I will also add that it can get confusing when someone replies to a
newsgroup posting that was originally suppressed to the mailing list.
This has happened as recently as today.

On Thu, 2021-05-06 at 14:36 +, Grant Edwards wrote:
> On 2021-05-06, Chris Angelico  wrote:
> > On Thu, May 6, 2021 at 10:43 AM Avi Gross via Python-list
> >  wrote:
> > > 
> > > Chris,
> > > 
> > > Given some notice, what stops anyone from joining the mailing
> > > list before
> > > there is a divorce between the forums?
> > 
> > Nothing! Nothing at all. That is, if you're talking about *people*.
> > People are absolutely welcome to join. The reason the S/N would
> > improve is all the non-people who post to the newsgroup.
> > 
> > But there are some people who simply don't want to use the mailing
> > list, and that's currently a fully-welcomed option. I won't name
> > names, but there definitely are people who would prefer a
> > newsreader,
> 
> Pointing a newsreader at news.gmane.io allows one to participate in
> the mailing list just fine without using Usenet.
> 
> Not that I support shutting down the Usenet/email gateway -- the
> signal/noise ration seems fine to me.
> 
> --
> Grant
> 
> 

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


Re: Proposal: Disconnect comp.lang.python from python-list

2021-05-05 Thread Paul Bryan
What's involved in moderating c.l.p? Would there be volunteers willing
to do so?

On Thu, 2021-05-06 at 00:43 +, Jon Ribbens via Python-list wrote:
> On 2021-05-06, Chris Angelico  wrote:
> > On Thu, May 6, 2021 at 10:32 AM Paul Bryan  wrote:
> > > 
> > > Given the ease of spoofing sender addresses, and its propensity
> > > for use
> > > in anonymous spamming and trolling (thanks python-list-owner for
> > > staying on top of that!), I propose to disconnect
> > > comp.lang.python from
> > > the python-list mailing list. Both would then operate
> > > independently.
> > > 
> > 
> > As someone who exclusively follows the mailing list, I selfishly
> > want
> > to support this, as it would notably improve the signal-to-noise
> > ratio. But I'm aware that there are a number of good people who
> > currently use the newsgroup, and those people would then be
> > abandoned
> > in the cess-pool.
> 
> Counter-proposal that I have suggested several times before that
> would
> solve both these problems: make the newsgroup moderated.
> 
> (Or, I suppose, create comp.lang.python.moderated and gateway it
> to the mailing list, and disconnect comp.lang.python from the list.)

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


Proposal: Disconnect comp.lang.python from python-list

2021-05-05 Thread Paul Bryan
Given the ease of spoofing sender addresses, and its propensity for use
in anonymous spamming and trolling (thanks python-list-owner for
staying on top of that!), I propose to disconnect comp.lang.python from
the python-list mailing list. Both would then operate independently.

Paul

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


Re: Not found in the documentation

2021-04-26 Thread Paul Bryan
I agree. I would be useful for it to be documented elsewhere,
especially in docstrings. I wonder if this is/was a conscious decision
to keep Python runtime smaller?

Paul

On Mon, 2021-04-26 at 18:24 -0700, elas tica wrote:
> Le mardi 27 avril 2021 à 01:44:04 UTC+2, Paul Bryan a écrit :
> > From
> > https://docs.python.org/3/reference/datamodel.html#the-standard-type-hierarchy
> >  
> > : 
> > 
> 
> 
> Thanks for the reference. I was expecting to find this information in
> the Built-in Types section from the PSL documentation. The
> representation returned by str over a complex number is not stated.
> The same for fraction objects. All the docstrinds are meaningless,
> showing :
> 
> __str__(self)
>     str(self)
> (END)
> 
> not very informative.

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


Re: Not found in the documentation

2021-04-26 Thread Paul Bryan
From 
https://docs.python.org/3/reference/datamodel.html#the-standard-type-hierarchy
:

> The string representations of the numeric classes, computed
> by__repr__() and __str__(), have the following properties:
>  * They are valid numeric literals which, when passed to their
>class constructor, produce an object having the value of the
>original numeric.
>  * The representation is in base 10, when possible.
>  * Leading zeros, possibly excepting a single zero before a
>decimal point, are not shown.
>  * Trailing zeros, possibly excepting a single zero after a
>decimal point, are not shown.
>  * A sign is shown only when the number is negative.

Paul

On Mon, 2021-04-26 at 16:24 -0700, elas tica wrote:
> 
> Python documentation doesn't seem to mention anywhere what is the str
> value of an int: is it right?  the same for float, Fraction, complex,
> etc? Not worth to be documented? Perphaps str(42) returns "forty two"
> or "XLII" or "101010" ...

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


Re: Current thinking on required options

2021-04-19 Thread Paul Bryan
Calling them options—when they're required—seems like a problem. 

On Mon, 2021-04-19 at 09:04 -0700, Dan Stromberg wrote:
> On Mon, Apr 19, 2021 at 2:55 AM Loris Bennett
> 
> wrote:
> 
> > However, the options -o, -u, and -g are required, not optional.
> > 
> > The documentation
> > 
> >   https://docs.python.org/3/library/argparse.html#required
> > 
> > advises against required options and here
> > 
> > 
> > https://stackoverflow.com/questions/24180527/argparse-required-arguments-listed-under-optional-arguments
> > 
> > a way of adding a section 'required arguments' to the usage is
> > described.
> > 
> 
> Of _course_ some options need to be required.
> 
> I can't imagine what the author of that page was thinking.

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


Re: Website

2021-04-14 Thread Paul Bryan
Yes.

On Wed, 2021-04-14 at 15:41 +0200, Rainyis wrote:
> Hello,
> I am Sergio Llorente, and I want to create a web about python. I
> will publish apps, scripts.. made by python. I will like to put
> python in
> the domain. The domain will be like all-about-python.com but in
> Spanish(
> todosobrepython.com). Can I use it?
> 
> Thanks in advance,
> Sergio

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


Re: question about basics of creating a PROXY to MONITOR network activity

2021-04-10 Thread Paul Bryan
Cloudflare operates as a reverse proxy in front of your service(s);
clients of your services access them through an endpoint that
Cloudflare stands up. DNS records point to Cloudflare, and TLS
certificates must be provisioned in Cloudflare to match. For all
intents and purposes, you would be outsourcing a part of your service
network infrastructure to Cloudflare.

Paul 

On Sat, 2021-04-10 at 13:35 -0500, Christian Seberino wrote:
> > 
> > a) your reverse proxy must be colocated with the service it fronts
> > on the same machine;
> > b) your network infrastructure transparently encrypts traffic
> > between your proxy and the service; or 
> > c) your proxy must negotiate its own TLS connection(s) with the
> > service.
> > 
> 
> 
> Paul
> 
> Thanks. I'm curious, do you know which of your options CloudFlare
> uses?  It has to stand in between
> you and all the sites you visit while allowing encryption right?
> 
> cs 

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


Re: question about basics of creating a PROXY to MONITOR network activity

2021-04-10 Thread Paul Bryan
There is absolutely nothing wrong with building your own reverse proxy
in front of your own service, as long as you control both. This
constitutes a tiered network/application architecture, and it's a
common practice. There's no man in the middle; there's no imposter; its
all "you". 

If your proxy becomes the endpoint that clients now must connect to
(i.e. nothing "in front" of your new proxy), you will have to deal with
TLS (aka SSL). Having the TLS certificate match the DNS address of your
new endpoint is a central tenet of security, and allows clients to
trust that they are connecting to the intended endpoint (there is
not a man in the middle).

How you secure the network traffic between your proxy and the service
it fronts becomes an important factor. If you claim that data is always
encrypted in transit, then either:

a) your reverse proxy must be colocated with the service it fronts on
the same machine;
b) your network infrastructure transparently encrypts traffic between
your proxy and the service; or 
c) your proxy must negotiate its own TLS connection(s) with the
service.

Negotiating TLS connections independently for each hop through a
network will add overhead, and degrade the performance of your service.
This can be major pain point when composing an application of
microservices, where each service must be able to securely connect to
another over a network. This is where a service mesh proxy (e.g. Envoy)
comes into play, or even full blown service mesh with service
discovery, certificate management, access policies (e.g. Istio). 


On Sat, 2021-04-10 at 07:52 -0700, cseb...@gmail.com wrote:
> 
> > Is it even possible to be secure in that way? This is, by
> > definition, 
> > a MITM, and in order to be useful, it *will* have to decrypt 
> > everything. So if someone compromises the monitor, they get 
> > everything. 
> 
> Chris
> 
> I hear all your security concerns and I'm aware of them.  I *really*
> don't want to have to
> fight SSL.  Encryption was the biggest concern and I'd rather not
> mess with it to do something 
> useful.
> 
> I've never used CloudFlare but if I'm not mistaken, it can be
> considered a useful "MITM" service?
> Do they have to decrypt traffic and increase the attack surface to be
> useful?
> 
> I just want to create a "safe" MITM service so to speak.
> 
> cs

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


Re: Problem in uninstalling python

2021-04-09 Thread Paul Bryan
Please describe your problem in detail.

Paul


On Fri, 2021-04-09 at 11:03 +0530, arishmallick...@gmail.com wrote:
>    I am encountering problem in uninstalling python. Please help me
> in this.
> 
> 
> 
>    Sent from [1]Mail for Windows 10
> 
> 
> 
> References
> 
>    Visible links
>    1. https://go.microsoft.com/fwlink/?LinkId=550986

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


Re: Code Formatter Questions

2021-03-28 Thread Paul Bryan
On Sun, 2021-03-28 at 15:42 +, Travis Griggs wrote:
> I've been looking into using a code formatter as a code base size has
> grown as well as contributing developers. I've found and played with
> autopep, black, and yapf. As well as whatever pycharm has (which may
> just be gui preferences around one of those 3).
> 
> I have 2 questions:
> 1) Are there any major other formatters that I can/should look at? I
> see some "online" pretty printers, but I'm after something I can run
> on whole recursive directories of code.

I assume you mean autopep8. I'm not aware of any other currently
popular formatters. 

> 2) I use more and type annotations (at least at the trivial level).
> But I like to have variable annotations tightly bound to the
> identifier, kind of like a subscript. So I want to see 
> 
>   def foo_bar(baz:int) -> bool:
>     yak:str = 'howdy mates'
> 
> And NOT 
> 
>   def foo_bar(baz: int) -> bool:
>     yak: str = 'howdy mates'
> 
> In other cases though (dictionaries for example), I'm fine with (and
> prefer) the spacing.
> 
> Is there anyway to make any of these formatters do this?

Formatters are typically strongly opinionated (autopep8 being an
exception), so I think you'll be going against the grain by trying to
make exceptions. I suggest accepting their opinions (pick the formatter
that most closely aligns with your taste), or, if you can make a case
for general use, suggest/request one change their opinions.

Paul

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


Re: .title() - annoying mistake

2021-03-21 Thread Paul Bryan
The topic of titles is complex, and would be significant undertaking to
automate. It's not only highly language-dependent, it's also based on
the subject work itself, and subject to guidelines of those charged
with indexing such works.

MusicBrainz guidelines:
https://wiki.musicbrainz.org/Style/Titles
https://wiki.musicbrainz.org/Style#Language_specific_guidelines

Wikipedia guidelines:
https://en.wikipedia.org/wiki/Wikipedia:Naming_conventions_(capitalization)
https://en.wikipedia.org/wiki/Wikipedia:Manual_of_Style/Titles#Capital_letters

Addressing such complexities isn't going to be baked into the
simplistic `str.title` method. As demonstrated by the OP, it will
almost certainly come up short, even in the simplest use case. I
suggest the best approach then is to find (or write) a module that
addresses the specific use case, not try to address such shortcomings
in `str`.

Paul

On Sun, 2021-03-21 at 23:01 +1100, Chris Angelico wrote:
> On Sun, Mar 21, 2021 at 10:31 PM Robert Latest via Python-list
>  wrote:
> > 
> > Chris Angelico wrote:
> > > On Sun, Mar 21, 2021 at 4:31 AM Robert Latest via Python-list
> > >  wrote:
> > > > 
> > > > Mats Wichmann wrote:
> > > > > The problem is that there isn't a standard for title case,
> > > > 
> > > > The problem is that we owe the very existence of the .title()
> > > > method to too
> > > > much weed being smoked during Python development. It makes
> > > > specific
> > > > assumptions about a specific use case of one specific language.
> > > > It doesn't
> > > > get more idiotic, frankly.
> > > > 
> > > 
> > > The problem is that you haven't read the documentation :) It very
> > > carefully
> > > does NOT define itself by language, and its behaviour is
> > > identical regardless
> > > of the language used.
> > 
> > The documentation says: "The algorithm uses a simple language-
> > independent
> > definition of a word as groups of consecutive letters..."
> > 
> > Yes, I get that. But the purpose it (improperly) serves only makes
> > sense in the
> > English language.
> 
> Why? Do titles not exist in other languages? Does no other language
> capitalize words in book or other titles?
> 
> ChrisA

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


Re: .title() - annoying mistake

2021-03-19 Thread Paul Bryan
From https://docs.python.org/3.9/library/stdtypes.html#str.title:

> The algorithm uses a simple language-independent definition of a word
> as groups of consecutive letters. The definition works in many
> contexts but it means that apostrophes in contractions and
> possessives form word boundaries, which may not be the desired result

The link above includes a workaround for apostrophes.

Paul

On Fri, 2021-03-19 at 18:43 +0400, Abdur-Rahmaan Janhangeer wrote:
> Greetings list,
> 
> See this:
> 
> > > > "Python's usage".title()
> "Python'S Usage"
> 
> It should have been Python's Usage
> 
> Why capitalise the S?
> 
> Kind Regards,
> 
> Abdur-Rahmaan Janhangeer
> about  | blog
> 
> github 
> Mauritius

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


Re: SSL certificate issue

2021-03-18 Thread Paul Bryan
In order for us to help, we'll need to know the details of your
problem.

On Thu, 2021-03-18 at 10:58 +, Sagar, Neha wrote:
> Hi,
> 
> I am facing SSL certificate issue working with python. Can you help
> me on this.
> 
> Thanks,
> Neha
> 
> DXC Technology India Private Limited - Unit 13, Block 2, SDF
> Buildings, MEPZ SEZ, Tambaram, Chennai 600 045, Tamil Nadu.
> Registered in India, CIN: U72900TN2015FTC102489.
> DXC Technology Company -- This message is transmitted to you by or on
> behalf of DXC Technology Company or one of its affiliates. It is
> intended exclusively for the addressee. The substance of this
> message, along with any attachments, may contain proprietary,
> confidential or privileged information or information that is
> otherwise legally exempt from disclosure. Any unauthorized review,
> use, disclosure or distribution is prohibited. If you are not the
> intended recipient of this message, you are not authorized to read,
> print, retain, copy or disseminate any part of this message. If you
> have received this message in error, please destroy and delete all
> copies and notify the sender by return e-mail. Regardless of content,
> this e-mail shall not operate to bind DXC Technology Company or any
> of its affiliates to any order or other contract unless pursuant to
> explicit written agreement or government initiative expressly
> permitting the use of e-mail for such purpose.

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


Re: Apriori Algorithm

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

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

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


Re: program python

2021-03-04 Thread Paul Bryan
I don't see a Python program in that link.

Are you asking how to extract data from a CSV?
A good start will be to look into the csv.reader function and
csv.DictReader class.

Paul

On Thu, 2021-03-04 at 12:36 -0800, alberto wrote:
> Hi I'm tring to write a program with python to evaluate data of csv
> data
> In particular I would extract this information 
> 
> View data on the presence of men and women in Affori over time.
> 
> * Carry out an analysis relating to the last available year. Of the
> 10 most populous neighborhoods show:
> * the proportion of births out of the total
> * the proportion of 80+ to the total
> * The ratio of minors / number of kindergartens
> 
> this is the file
> https://drive.google.com/file/d/1zKflvSpB-oDAqYscLsEgUhSnqL1XPdql/view?usp=sharing
> 
> How could fix it?
> 
> regards 

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


[issue43345] Add __required_keys__ and __optional_keys__ to TypedDict documentation

2021-02-27 Thread Paul Bryan


Change by Paul Bryan :


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

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



[issue43345] Add __required_keys__ and __optional_keys__ to TypedDict documentation

2021-02-27 Thread Paul Bryan


Change by Paul Bryan :


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

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



[issue43345] Add __required_keys__ and __optional_keys__ to TypedDict documentation

2021-02-27 Thread Paul Bryan


Change by Paul Bryan :


--
nosy: +gvanrossum

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



[issue43345] Add __required_keys__ and __optional_keys__ to TypedDict documentation

2021-02-27 Thread Paul Bryan


New submission from Paul Bryan :

>From Typing-sig list:

On Thu, Feb 11, 2021 at 10:54 PM Paul Bryan  wrote:
> I don't think __required_keys__ or __optional_keys__ are documented, at least 
> not in https://docs.python.org/3.10/library/typing.html. Is there any reason 
> we can't codify them in 3.10 docs?

On Fri, 2021-02-12 at 14:23 -0800, Guido van Rossum wrote:
> Nobody got to it yet? Maybe you'd be willing to submit a small PR for this?

--
assignee: docs@python
components: Documentation
messages: 387802
nosy: docs@python, pbryan
priority: normal
severity: normal
status: open
title: Add __required_keys__ and __optional_keys__ to TypedDict documentation
versions: Python 3.10

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



Re: Fw: Scipy installation

2021-02-18 Thread Paul Bryan
Can you describe what you tried, and how it failed? Pasting error
messages and such would be helpful.

On Thu, 2021-02-18 at 17:53 +, Mustafa Althabit via Python-list
wrote:
>  
> 
>    Hi,I am trying to install Scipy but it failed, I have python
> 3.9. I need your assistance with that. 
> Thank you Mustafa Althabit8133825988  

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


Re: New Python implementation

2021-02-11 Thread Paul Bryan
On Thu, 2021-02-11 at 17:56 +, Mr Flibble wrote:

> Actually it is a relatively small task due to the neos universal
> compiler's architectural design.  If it was a large task I wouldn't
> be doing it.

When do you estimate this task will be completed?

> I am not particularly interested in any of the existing
> implementations as they bear no relation to the design of my language
> agnostic universal compiler, runtime, VM and JIT; the only use they
> will have will be to disambiguate certain Python language constructs
> that I cannot disambiguate from documentation alone: this is a
> natural consequence of Python not being standardized; those steering
> the language need to grow a pair and get Python standardized
> preferably as an ISO Standard.

I take it you don't hope to receive any support from those you're
insulting by such a statement?

> Thanks for the sentiment but I am not relying on luck.

By your conduct so far, I think you will also not be relying on the
goodwill of this community.

Paul

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


Re: Mutable defaults

2021-02-10 Thread Paul Bryan
Also -1 on changing the existing default behavior. +1 to an opt-in
late-bound solution.

On Thu, 2021-02-11 at 10:29 +1100, Chris Angelico wrote:
> On Thu, Feb 11, 2021 at 10:17 AM J. Pic  wrote:
> > 
> > > Most of us know of the perils of mutable default values.
> > 
> > And those who don't pay the price.
> > 
> > I wonder what would be the harm in removing them
> 
> Define "removing". Most objects in Python are mutable; would that
> mean
> you can no longer use any custom class, or any object at all that has
> a __dict__, as a default?
> 
> > or doing copy on call by default.
> 
> I assume you are referring only to argument defaults, because
> copy-on-call for ALL parameters would be ridiculously costly, not to
> mention problematic in many ways.
> 
> The main problem is that mutable defaults are only very rarely an
> issue (for starters, you have to actually mutate the object - just
> because it's mutable, that doesn't mean you'll change anything), but
> any global "solution" to the "problem" is going to have a very high
> global cost. Not every mutable object is copyable. And it would have
> to be a deep copy (in case, for instance, the default is a tuple
> containing a list), which has even more cost.
> 
> Strongly -1 on any proposal to change the defaults.
> 
> Now, if you're interested in some kind of proposal for opt-in
> late-bound defaults, I think there'd be some value in researching
> that. It would probably require language support, but there'd be a
> few
> potential advantages:
> 
> 1) The function signature would actually say the real default. For
> instance, "def flurble(stuff=[]):" shows that the default is a list,
> but "def flurble(stuff=None): if stuff is None: stuff = []" doesn't.
> 2) This could be more flexible than just copying. The default could
> simply be an expression that's evaluated at call time, and could even
> refer to other arguments (eg "def frob(things, start=0,
> stop=len(things)):"), and, again, the displayed signature would show
> the real default, instead of some placeholder.
> 3) It's far cleaner to read a coherent function signature than to
> have
> to read a handful of lines at the top of the function. That's why we
> have defaults in the first place.
> 
> But this would depend heavily on finding a really good syntax for it.
> It's been investigated at times, but no proposal has ever been strong
> enough to push forward. Feel free to try a few things out, see if you
> can find something that makes sense.
> 
> ChrisA

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


[issue42269] Add ability to set __slots__ in dataclasses

2021-02-07 Thread Paul Bryan


Change by Paul Bryan :


--
nosy: +pbryan

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



Re: Python cannot count apparently

2021-02-07 Thread Paul Bryan
That's not the only problem with the code. There's a missing close-
paren and a reference to "string" which I presume was meant to be
"myString".

Suggest OP create a reproducible case, and paste the code and output
verbatim.


On Sun, 2021-02-07 at 20:40 +0100, Karsten Hilbert wrote:
> Am Sun, Feb 07, 2021 at 08:34:34PM +0100 schrieb Philipp Daher via
> Python-list:
> 
> > I recently coded this snippet of code:
> > myString=„hello“
> 
> I doubt you have (coded *this* snippet of code) -- because
> those quotes wouldn't work.
> 
> Karsten
> --
> GPG  40BE 5B0E C98E 1713 AFA6  5BC0 3BEA AC80 7D4F C89B

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


Re: IDE tools to debug in Python?

2021-01-27 Thread Paul Bryan via Python-list
My experience with IntelliJ (related to PyCharm): it scans all source
files in the project, compiles them, graphs all dependencies, compiles
those (if necessary) or inspects their class bytecode, and so on to
build a full graph in memory to support showing errors in real time
(highlighting in source) and autocomplete when user is typing. In my
experience, it's heavyweight, and creates more reliance on the features
of an IDE than I feel is healthy (IDE becomes a crutch). I suspect
PyCharm is doing much of the same.

On Wed, 2021-01-27 at 15:36 -0500, C W wrote:
> I don't know exactly, but it shows as inspection on the bottom left
> corner.
> 
> I believe it's indexing in the background.
> 
> On Wed, Jan 27, 2021 at 3:25 PM Grant Edwards
> 
> wrote:
> 
> > On 2021-01-27, C W  wrote:
> > > I'm not expert in Python, but I sure tried many IDEs to kick off
> > > Python
> > > programming.
> > > 
> > > I started with PyCharm, but I had a problem with it constantly
> > > scanning
> > the
> > > background, even after I turned that feature off.
> > 
> > What is it scanning?
> > 
> > > My favorite (I'm using now) is VS Code with Python extension,
> > > it's very
> > > light. Recently also started background scanning, but that's
> > > generally
> > done
> > > in 30 seconds.
> > 
> > Same question, what is it scanning?
> > 
> > --
> > Grant
> > 
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> > 

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


[issue33129] Add kwarg-only option to dataclass

2021-01-25 Thread Paul Bryan


Change by Paul Bryan :


--
nosy: +pbryan

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



[issue42904] get_type_hints does not provide localns for classes

2021-01-11 Thread Paul Bryan


Change by Paul Bryan :


--
nosy: +larry

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



[issue42904] get_type_hints does not provide localns for classes

2021-01-11 Thread Paul Bryan


New submission from Paul Bryan :

According to PEP 563:

> The get_type_hints() function automatically resolves the correct value of 
> globalns for functions and classes. It also automatically provides the 
> correct localns for classes.

This statement about providing correct localns for classes does not appear to 
be true.

Guido suggested this should be treated as a bug.

--
components: Library (Lib)
messages: 384885
nosy: gvanrossum, pbryan
priority: normal
severity: normal
status: open
title: get_type_hints does not provide localns for classes
type: behavior
versions: Python 3.10

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



[issue42662] Propose: Data model explict about __annotations__ key ordering.

2020-12-16 Thread Paul Bryan


Paul Bryan  added the comment:

Retracting.

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

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



[issue42662] Propose: Data model explict about __annotations__ key ordering.

2020-12-16 Thread Paul Bryan


Change by Paul Bryan :


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

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



[issue42662] Propose: Data model explict about __annotations__ key ordering.

2020-12-16 Thread Paul Bryan


New submission from Paul Bryan :

Currently the data model documentation does not specify the order of keys in 
__annotations__ dictionary. It is currently in the order that arguments or 
attributes are declared. I propose to make this explicit.

Rationale: Having order explicitly specified in the documentation makes it a 
documented feature that code can depend on. Current code cannot safely rely on 
this behavior.

--
assignee: docs@python
components: Documentation
messages: 383204
nosy: docs@python, pbryan
priority: normal
severity: normal
status: open
title: Propose: Data model explict about __annotations__ key ordering.
versions: Python 3.10

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



Re: dict.get(key, default) evaluates default even if key exists

2020-12-16 Thread Paul Bryan
Maybe this will help:

>>> def get(key, default):
...   print("entering get")
...   print(f"{key=} {default=}")
...   print("exiting get")
... 
>>> def generate_default():
...   print("entering generate_default")
...   print("exiting generate_default")
...   return 1
... 
>>> get("a", generate_default())
entering generate_default
exiting generate_default
entering get
key='a' default=1
exiting get
>>> 

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


Re: dict.get(key, default) evaluates default even if key exists

2020-12-16 Thread Paul Bryan
On Wed, 2020-12-16 at 10:01 +0100, Loris Bennett wrote:

> OK, I get the point about when the default value is generated and
> that
> potentially being surprising, but in the example originally given,
> the
> key 'a' exists and has a value of '1', so the default value is not
> needed.

But the function is still called. The get method just doesn't use (or
return) the value it generates because the key exists. Nevertheless,
you're passing the return value of the get_default function as an
argument.

> Thus, I am still unsurprised when dict.get returns the value of an
> existing key.

As am I.

> What am I missing?

You'll need to tell me at this point.

Paul

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


Re: dict.get(key, default) evaluates default even if key exists

2020-12-16 Thread Paul Bryan
On Wed, 2020-12-16 at 08:59 +0100, Loris Bennett wrote:

> Isn't the second argument to D.get() the value to be return if the
> first
> argument is not a valid key?  In that case, why does it make any
> difference here what the second argument of D.get() is since the key
> 'a'
> does exist?
> 
> Thus, I would indeed expect the code above to print '1'.  I am
> obviously
> missing something here.

Yes, the second argument is what to return if there is no valid key.
The second argument is evaluated before the call to the get function.
It's return value is being supplied as an argument to the get function.

Let's write a couple of quick functions to demonstrate...

>>> def get(key, default):
...   print(f"{key=} {default=}")
... 
>>> def generate_a_default_value():
...   return 1
... 
>>> get("a", generate_a_default_value())
key='a' default=1
>>> 

The generate_a_default_value function was called before the call to
get. It was called so it could produce a value that is actually passed
in as an argument to the get function.

Paul

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


Re: Function returns old value

2020-12-11 Thread Paul Bryan
Sorry, actually, if you do not answer yes, will always return None, not
the first answer as I suggested.

On Fri, 2020-12-11 at 18:55 -0700, Joe Pfeiffer wrote:
> Bischoop  writes:
> 
> > I've function asking question and comparing it, if is not matching
> > 'yes'
> > it does call itself to ask question again. The problem is that when
> > function is called second time it returns old value or with
> > additional
> > else statement it returns none.
> > 
> > Code: https://bpa.st/KVGA
> 
> It calls itself again, but what does it return in that case?

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


Re: Function returns old value

2020-12-11 Thread Paul Bryan
It won't return until the inner call to question (and it's not using
the return value on inner call). Eventually, (and not until you answer
yes) it will return the first answer.

On Fri, 2020-12-11 at 18:55 -0700, Joe Pfeiffer wrote:
> Bischoop  writes:
> 
> > I've function asking question and comparing it, if is not matching
> > 'yes'
> > it does call itself to ask question again. The problem is that when
> > function is called second time it returns old value or with
> > additional
> > else statement it returns none.
> > 
> > Code: https://bpa.st/KVGA
> 
> It calls itself again, but what does it return in that case?

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


Re: Property type hints?

2020-12-09 Thread Paul Bryan
Thanks for the comprehensive response, dn!

I guess I'm influenced by data classes here, where the object's
attribute type hints are represented by class variable annotations.


On Thu, 2020-12-10 at 07:49 +1300, dn via Python-list wrote:
> On 09/12/2020 13:17, Paul Bryan wrote:
> > Would this be a reasonably correct way to annotate a property with
> > a
> > type hint?
> > 
> > > > > class Foo:
> > ... bar: int
> 
> 
> If we build a class with (only) the above two lines, Python's help 
> lookup offers the following documentation:
> 
> <<<
> Help on Foo in module __main__ object:
> 
> class Foo(builtins.object)
>   |  Data descriptors defined here:
>   |
>   |  __dict__
>   |  dictionary for instance variables (if defined)
>   |
>   |  __weakref__
>   |  list of weak references to the object (if defined)
>   |
>   |  
> --
>   |  Data and other attributes defined here:
>   |
>   |  __annotations__ = {'bar': }
>  >>>
> 
> Note the last line identifying 'bar' as having integer-type.
> 
> However, when we continue, by adding a property/lookup-method called
> 'bar'.
> 
> > ... @property
> > ... def bar(self):
> > ... return 1
> 
> 
> ...the help lookup becomes:
> 
> <<<
> class Foo(builtins.object)
>   |  Readonly properties defined here:
>   |
>   |  bar
>   |
>   |  
> --
>   |  Data descriptors defined here:
>   |
>   |  __dict__
>   |  dictionary for instance variables (if defined)
>   |
>   |  __weakref__
>   |  list of weak references to the object (if defined)
>   |
>   |  
> --
>   |  Data and other attributes defined here:
>   |
>   |  __annotations__ = {'bar': }
>  >>>
> 
> Note that 'bar' has now been listed as a read-only property.
> 
> Further, if we remove the explicit typing (int) of 'bar', the help 
> listing doesn't change.
> 
> 
> <<<
> class Foo(builtins.object)
>   |  Readonly properties defined here:
>   |
>   |  bar
>   |
>   |  
> --
>   |  Data descriptors defined here:
>   |
>   |  __dict__
>   |  dictionary for instance variables (if defined)
>   |
>   |  __weakref__
>   |  list of weak references to the object (if defined)
>  >>>
> 
> Except that the annotation documentation has disappeared!
> 
> Hence, one assumes, the question!
> 
> The problem is that the help system appears to be talking about two 
> different things: 'bar' the class int, and 'bar' the method/property.
> At 
> run-time however, there cannot be two uses of the same name, and the 
> last-defined 'wins'.
> 
> Continuing:-
> 
> > ...
> > > > > foo = Foo()
> > > > > import typing
> > > > > typing.get_type_hints(foo)
> > {'bar': }
> > 
> > I could also decorate the property method return value:
> > ... def bar(self) -> int:
> 
> ...and when the typing-hint is added to the property's def, the help 
> listing still doesn't change/improve.
> 
> 
> That said, I've been following this last convention since moving to
> typing.
> 
> Putting a separate description at the beginning of the class invites
> the 
> reader to think of 'foo' as an integer. That's not 'wrong', in the
> sense 
> that a property is/produces an attribute in the same dotted-notation 
> from the object-name. However,there could be quite a lot of code
> between 
> this 'declaration' line and the property def!
> 
> However, there is another line of logic built upon the idea that all 
> class-attributes should be defined in the class 'header' and all 
> instance-attributes in __init__() or __post_init__(). Does this
> underlie 
> the discussion?
> 
> 
> > I don't see the point though, because you can't access it with
> > get_type_hints.
> 
> Correct: if one codes (only) the property-bar, then:
> 
>  >>> get_type_hints( Foo )
> {}
> 
> However, reverting back to the first class-definition, we do see 
> something for our money:
> 
>  >>> get_type_hints( foo )
> {'bar': }
> 
> Unfortunately, as mentioned above, there is this confusion between
> the 
> two 'bar's...
> 
> Proof?
> 
> If we change things, the result is not what (it would appear) is
> desired:
> 
>  >>> class Foo:
> ...   bar:str
> ...   @pro

Property type hints?

2020-12-08 Thread Paul Bryan
Would this be a reasonably correct way to annotate a property with a
type hint?

>>> class Foo:
... bar: int
... @property
... def bar(self):
... return 1
... 
>>> foo = Foo()
>>> import typing
>>> typing.get_type_hints(foo)
{'bar': }

I could also decorate the property method return value:
... def bar(self) -> int:

I don't see the point though, because you can't access it with get_type_hints.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue42592] TypedDict: total=False but still key required

2020-12-07 Thread Paul Bryan


Paul Bryan  added the comment:

Your patch LGTM, Brandt.

--

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



[issue42592] TypedDict: total=False but still key required

2020-12-07 Thread Paul Bryan


New submission from Paul Bryan :

I believe "a" below should be an optional key, not a required one.

Python 3.9.0 (default, Oct  7 2020, 23:09:01) 
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import typing
>>> TD = typing.TypedDict("TD", {"a": str}, total=False)
>>> TD.__total__
False
>>> TD.__required_keys__
frozenset({'a'})
>>> TD.__optional_keys__
frozenset()
>>>

--
components: Library (Lib)
messages: 382662
nosy: gvanrossum, pbryan
priority: normal
severity: normal
status: open
title: TypedDict: total=False but still key required
type: behavior
versions: Python 3.9

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



Re: help(list[int]) → TypeError

2020-12-04 Thread Paul Bryan
Thanks, will bring it to the dev list.

On Fri, 2020-12-04 at 07:07 -0800, Julio Di Egidio wrote:
> On Thursday, 3 December 2020 at 19:28:19 UTC+1, Paul Bryan wrote:
> > Is this the correct behavior? 
> > 
> > Python 3.9.0 (default, Oct 7 2020, 23:09:01) 
> > [GCC 10.2.0] on linux 
> > Type "help", "copyright", "credits" or "license" for more
> > information. 
> > > > > help(list[int]) 
> > Traceback (most recent call last): 
> > File "", line 1, in  
> > File "/usr/lib/python3.9/_sitebuiltins.py", line 103, in __call__ 
> > return pydoc.help(*args, **kwds) 
> > File "/usr/lib/python3.9/pydoc.py", line 2001, in __call__ 
> > self.help(request) 
> > File "/usr/lib/python3.9/pydoc.py", line 2060, in help 
> > else: doc(request, 'Help on %s:', output=self._output) 
> > File "/usr/lib/python3.9/pydoc.py", line 1779, in doc 
> > pager(render_doc(thing, title, forceload)) 
> > File "/usr/lib/python3.9/pydoc.py", line 1772, in render_doc 
> > return title % desc + '\n\n' + renderer.document(object, name) 
> > File "/usr/lib/python3.9/pydoc.py", line 473, in document 
> > if inspect.isclass(object): return self.docclass(*args) 
> > File "/usr/lib/python3.9/pydoc.py", line 1343, in docclass 
> > (str(cls.__name__) for cls in type.__subclasses__(object) 
> > TypeError: descriptor '__subclasses__' for 'type' objects doesn't
> > apply to a 'types.GenericAlias' object 
> > > > > 
> > 
> > I would have expected the output to the identical to help(list).
> 
> As I get it from the docs (*), these new generics still only work in
> type hinting contexts,
> and I'd rather have expected a more useful error message: but,
> whether that is temporary
> (possibly a plain bug, as in a forgotten case) or, instead, just "how
> things are", I wouldn't
> know... might be a good question for Python developers.
> 
> (*) As in this one for a starter, but see also PEP 585:
> "*In type annotations* you can now use ...", my emphasis.
> <https://docs.python.org/3.9/whatsnew/3.9.html#type-hinting-generics-in-standard-collections
> >
> 
> Julio

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


Re: list[type, type, ...] ?!

2020-12-03 Thread Paul Bryan
Thanks, Greg. Would it make sense for list's __class_getitem__
(GenericAlias?) to perform similar checking as
typing._SpecialGenericAlias (nparams)?

On Fri, 2020-12-04 at 12:15 +1300, Greg Ewing wrote:
> On 3/12/20 7:37 pm, Paul Bryan wrote:
> > > > > list[int, int]
> > list[int, int]
> > 
> > In fact, it appears I can specify an indeterminate number of types.
> 
> I think the built-in generic alias just provides the minimum
> necessary to be able to write sometype[arg, ...]. It doesn't
> know anything about the semantics with respect to particular
> types -- that's left to the type checkers.
> 
> -- 
> Greg

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


help(list[int]) → TypeError

2020-12-03 Thread Paul Bryan
Is this the correct behavior?

Python 3.9.0 (default, Oct  7 2020, 23:09:01) 
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> help(list[int])
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python3.9/_sitebuiltins.py", line 103, in __call__
return pydoc.help(*args, **kwds)
  File "/usr/lib/python3.9/pydoc.py", line 2001, in __call__
self.help(request)
  File "/usr/lib/python3.9/pydoc.py", line 2060, in help
else: doc(request, 'Help on %s:', output=self._output)
  File "/usr/lib/python3.9/pydoc.py", line 1779, in doc
pager(render_doc(thing, title, forceload))
  File "/usr/lib/python3.9/pydoc.py", line 1772, in render_doc
return title % desc + '\n\n' + renderer.document(object, name)
  File "/usr/lib/python3.9/pydoc.py", line 473, in document
if inspect.isclass(object): return self.docclass(*args)
  File "/usr/lib/python3.9/pydoc.py", line 1343, in docclass
(str(cls.__name__) for cls in type.__subclasses__(object)
TypeError: descriptor '__subclasses__' for 'type' objects doesn't apply to a 
'types.GenericAlias' object
>>> 

I would have expected the output to the identical to help(list).
-- 
https://mail.python.org/mailman/listinfo/python-list


list[type, type, ...] ?!

2020-12-03 Thread Paul Bryan
Using the typing.List generic alias, I can only specify a single type.
Example:

>>> typing.List[int]
typing.List[int]

When I try to specify additional types, it fails. Example:

>>> typing.List[int, int]
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python3.9/typing.py", line 243, in inner
return func(*args, **kwds)
  File "/usr/lib/python3.9/typing.py", line 775, in __getitem__
_check_generic(self, params, self._nparams)
  File "/usr/lib/python3.9/typing.py", line 197, in _check_generic
raise TypeError(f"Too {'many' if alen > elen else 'few'} parameters for 
{cls};"
TypeError: Too many parameters for typing.List; actual 2, expected 1

This makes sense to me. An item has one type, and we use Union if we
want variants. What's not making sense to me in Python 3.9: I can use
the built-in generic alias in list in this manner, apparently
successfully:

>>> list[int, int]
list[int, int]

In fact, it appears I can specify an indeterminate number of types. Can
someone explain what this construct means? I suspect this will fail to
be interpreted by type validators, but wonder why it doesn't fail fast
when I express it.

Thanks,

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


[issue15873] datetime: add ability to parse RFC 3339 dates and times

2015-03-05 Thread Paul Bryan

Changes by Paul Bryan pbr...@anode.ca:


--
nosy: +pbryan

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