Fwd: A typing question

2022-10-29 Thread Sam Ezeh
Do you want the following?

```
from typing import List, Optional


class GLOBALS:
foos: Optional[Foos] = None


class Foo:
def __init__(self):
pass


class Foos:
Foos: List[Foo] = []

def __init__(self):
pass


GLOBALS.foos = Foos()
```

Kind regards,
Sam Ezeh

On Sat, 29 Oct 2022 at 22:13, Paulo da Silva <
p_d_a_s_i_l_v_a...@nonetnoaddress.pt> wrote:

> Hi!
>
> Consider this simple script ...
>
> ___
> from typing import List, Optional
>
> class GLOBALS:
>  foos=None
>
> class Foo:
>
>  def __init__(self):
>  pass
>
> class Foos:
>  Foos: List[Foo]=[]
>  # SOME GLOBALS ARE USED HERE in a real script
>
>  def __init__(self):
>  pass
>
> GLOBALS.foos: Optional[Foos]=Foos()
> ___
>
> Running mypy on it:
> pt9.py:18: error: Type cannot be declared in assignment to non-self
> attribute
> pt9.py:18: error: Incompatible types in assignment (expression has type
> "Foos", variable has type "None")
> Line  18 is last line and pt9.py is the scrip.
>
> Replacing last line by
> GLOBALS.foos=Foos()
> and running mypy still gives the second error.
> pt9.py:18: error: Incompatible types in assignment (expression has type
> "Foos", variable has type "None")
>
> What is the common practice in these cases?
>
> Thank you.
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Virtual PUG-meeting: An applied introduction to Finite State Machines

2022-09-13 Thread Sam Ezeh
That seems interesting.

Is this hosted online? And are there any suggested reading materials for
those who might not be able to attend?

Kind regards,
Sam Ezeh

On Tue, 13 Sept 2022 at 22:53, dn  wrote:

> An applied introduction to Finite State Machines
> 0730 UTC, Wed 21 Sep 2022
>
> The basics of Finite State Machines and what they are good for. How to
> use FSM for solving optimization problems.
>
> - A simple traffic jam
> - A bigger traffic jam
> - A sudoku
>
> After this lecture there won't be any discrete optimization problem you
> won't be able to solve.
>
> Dr. Bjorn Madsen solves optimization problems using Python, for DoD,
> LEGO, Coca Cola, Airbus and many other companies.
>
>
> These meetups have two sessions. At least one is aimed at a beginner
> level - in either Python or FSMs.
>
> Sign-up and more details from https://www.meetup.com/nzpug-auckland/
> --
> Regards,
> =dn
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Building on Windows

2022-07-02 Thread Sam Ezeh
To add to this, my process was

1. Setup the VM
2. Install Git
3. Clone CPython
4. Run `PCbuild\build.bat -d -e`
5. Notice the error, then install visual studio community 2022
6. Re-run `PCbuild\build.bat -d -e` and see the same error

I can't directly copy and paste between the VM and my host desktop but
in this scenario, the error was that single line and I can use paste
sites where necessary.

Kind regards,
Sam Ezeh

On Sat, 2 Jul 2022 at 15:27, Sam Ezeh  wrote:
>
> I have a Windows virtual machine and I'm following the instructions on
> the devguide [1] to build Python inside it.
>
> When running `PCbuild\build\bat -e -d` I get "Cannot locate
> MSBuild.exe on PATH or as MSBUILD variable". I've done a minimal
> amount of searching [2][3] but I'm not well-acquainted with Windows
> and don't understand the solutions.
>
> Thanks in advance.
>
> Kind regards,
> Sam Ezeh
>
> [1]: https://devguide.python.org/compiler/
> [2]: https://bugs.python.org/issue41213
> [3]: https://bugs.python.org/issue33675
-- 
https://mail.python.org/mailman/listinfo/python-list


Building on Windows

2022-07-02 Thread Sam Ezeh
I have a Windows virtual machine and I'm following the instructions on
the devguide [1] to build Python inside it.

When running `PCbuild\build\bat -e -d` I get "Cannot locate
MSBuild.exe on PATH or as MSBUILD variable". I've done a minimal
amount of searching [2][3] but I'm not well-acquainted with Windows
and don't understand the solutions.

Thanks in advance.

Kind regards,
Sam Ezeh

[1]: https://devguide.python.org/compiler/
[2]: https://bugs.python.org/issue41213
[3]: https://bugs.python.org/issue33675
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python installation

2022-06-21 Thread Sam Ezeh
Inside my Windows virtual machine only entering `py` as the command
brings up the repl, if that helps.

Kind Regards,
Sam Ezeh

On Tue, 21 Jun 2022 at 18:15, Igor Korot  wrote:
>
> Hi,
>
> On Tue, Jun 21, 2022 at 11:43 AM 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.
>
> Is it possible that Python is already installed?
>
> Open "Command Prompt" window, type python and press "Enter".
>
> What do you see on the screen?
>
> Thank you.
>
> >
> > I look forward to hearing from you.
> >
> > Thank you,
> > Brian.
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Seeking deeper understanding of python equality (==)

2022-05-06 Thread Sam Ezeh
Perhaps these source references are useful:

Python/ceval.c (_PyEval_EvalFrameDefault)
https://github.com/python/cpython/blob/main/Python/ceval.c#L3754-L3768
Objects/object.c (do_richcompare)
https://github.com/python/cpython/blob/42fee931d055a3ef8ed31abe44603b9b2856e04d/Objects/object.c#L661-L713

Kind regards,
Sam Ezeh


On Fri, 6 May 2022 at 18:12, Jonathan Kaczynski
 wrote:
>
> Hi,
>
> I was recently trying to explain how python equality works and ran into a
> gap in my knowledge. I haven't found any good pages going beneath a surface
> level explanation of python equality comparison.
>
> I'll post my investigations below. What I think I'm looking for is where in
> the source code (https://github.com/python/cpython) does the equality
> comparison occur. I have an idea but wanted to ask first.
>
>
> Using the dis module, we see the comparison operator is a single bytecode,
> which is expected.
>
> ❯ docker run -it --rm ubuntu:jammy
> root@919d94c98191:/# apt-get update
> root@919d94c98191:/# apt-get --yes install python3
> root@919d94c98191:/# cat >play.py < import dis
> import uuid
>
> def test():
> x = uuid.uuid4()
> y = str(x)
> x == y
> return
>
> dis.dis(test)
> EOF
> root@f33b02fef026:/# python3 play.py
> ... snip ...
>   7  16 LOAD_FAST0 (x)
>  18 LOAD_FAST1 (y)
>  20 COMPARE_OP   2 (==)
>  22 POP_TOP
> ... snip ...
>
>
> Stepping through the code with gdb, we see it jump from the compare
> operator to the dunder-eq method on the UUID object. What I want to be able
> to do is explain the in-between steps. Also, if you change `x == y` to `y
> == x`, you still see the same behavior, which I assume has to do with
> dunder-eq being defined on the UUID class and thus given priority.
>
> ❯ docker run -it --rm ubuntu:jammy
> root@919d94c98191:/# apt-get update
> root@919d94c98191:/# apt-get --yes install dpkg-source-gitarchive
> root@919d94c98191:/# sed -i 's/^# deb-src/deb-src/' /etc/apt/sources.list
> root@919d94c98191:/# apt-get update
> root@919d94c98191:/# apt-get --yes install gdb python3.10-dbg
> root@919d94c98191:/# apt-get source python3.10-dbg
> root@919d94c98191:/# cat >play.py < import uuid
> x = uuid.uuid4()
> y = str(x)
> breakpoint()
> x == y
> EOF
> root@919d94c98191:/# gdb python3.10-dbg
> (gdb) dir python3.10-3.10.4/Python
> (gdb) run play.py
> Starting program: /usr/bin/python3.10-dbg play.py
>
> warning: Error disabling address space randomization: Operation not
> permitted
> [Thread debugging using libthread_db enabled]
> Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
> > //play.py(5)()
> -> x == y
> (Pdb) s
> --Call--
> > /usr/lib/python3.10/uuid.py(239)__eq__()
> -> def __eq__(self, other):
>
>
> Thank you,
> Jonathan
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Fwd: Do projects exist to audit PyPI-hosted packages?

2022-05-06 Thread Sam Ezeh
-- Forwarded message -
From: Sam Ezeh 
Date: Fri, 6 May 2022, 15:29
Subject: Re: Do projects exist to audit PyPI-hosted packages?
To: Skip Montanaro 


I've had similar thoughts in the past. I don't know of anything but I
wonder if repositiories for other languages might have something to deal
with it.

A related problem is that even if a package is maintained by somebody with
good intentions, the account might be hijacked by a malicious actor and
since PyPi is separate from source control, people might not be able to
find out easily and malware could spread through PyPi.

Kind regards,
Sam Ezeh


On Fri, 6 May 2022, 14:08 Skip Montanaro,  wrote:

> I woke with a start in what amounted to the middle of the night (I really
> need to get about three more hours of sleep, but you'll understand why I
> was awake to write this).
>
> Many years ago, so as to preserve my wrists, I wrote a tool
> <https://github.com/smontanaro/python-bits/blob/main/src/watch.py> to
> monitor mouse and keyboard activity. It tells me when to rest. I use it
> when I have problems, then put it away until it's needed again. I have
> resurrected it a few times over the years, most recently a month or two
> ago. Having never been all that fond of how I tracked keyboard and mouse
> activity, I was happy when I stumbled upon pynput
> <https://pypi.org/project/pynput/>. "Yay!", I thought. My worries are
> over.
>
> Then extremely early this morning I woke thinking, "Damn, this runs on my
> computer and it can see my mouse and keyboard activity. How do I know it's
> not stealing my keystrokes?" Not going back to sleep after that. So, I'm
> going through the code (and the Xlib package on which it relies) to make
> myself more comfortable that there are no issues. Note: I am *most
> certainly not* accusing the pynput author of any mischief. In fact, I
> suspect there's no problem with the package. It's got a bunch of stars and
> plenty of forks on GitHub (for what that's worth). I suspect the code has
> had plenty of eyeballs looking at it. Still, I don't really know how well
> vetted it might be, so I have no assurances of that. I saw it mentioned
> somewhere (discuss I think?), checked it out, and thought it would solve my
> activity tracking in a cross-platform way. (I currently only use an Xorg
> environment, so while I am looking at the code, I'm not paying attention to
> the Windows or MacOS bits either.)
>
> This got me thinking. If I'm curious about pynput, might other people be as
> well? What about other packages? I'm actually not worried about Python
> proper or vulnerabilities which have already been found
> <https://github.com/pypa/advisory-database>. PyPI currently advertises
> that
> it hosts over 373k packages. With that many hosted packages, it is almost
> certainly a haven for some undetected vulnerabilities. Knowing which
> packages have been audited — at least in a cursory fashion — could be used
> as a further criterion to use when deciding which packages to consider
> using on a project.
>
> So, does something already exist (pointers appreciated)? Thx...
>
> Skip
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why no list as dict key?

2022-04-20 Thread Sam Ezeh
Repeating the above points, here is an example of what would happen if
you tried. Dictionaries require their keys to be immutable as
under-the-hood they use hash tables and they'd fail when the
underlying values are allowed to change.

```
[sam@samtop]: ~>$ python
Python 3.10.2 (main, Jan 15 2022, 19:56:27) [GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import functools
>>> import operator
>>> class HashableList(list):
... def __hash__(self):
... return functools.reduce(operator.xor, [key * value for
key, value in enumerate(self)], 5)
...
>>> x = HashableList([1,2,3])
>>> y = HashableList([1,2,3])
>>> dictionary = {x: 5}
>>> dictionary
{[1, 2, 3]: 5}
>>> dictionary[x]
5
>>> dictionary[y]
5
>>> x.append(4)
>>> dictionary
{[1, 2, 3, 4]: 5}
>>> dictionary[x]
Traceback (most recent call last):
  File "", line 1, in 
KeyError: [1, 2, 3, 4]
>>> dictionary[y]
Traceback (most recent call last):
  File "", line 1, in 
KeyError: [1, 2, 3]
>>>
```

On Wed, 20 Apr 2022 at 19:23, Abdur-Rahmaan Janhangeer
 wrote:
>
> Greetings list,
>
> Using Python3.9, i cannot assign a list [1, 2] as key
> to a dictionary. Why is that so? Thanks in advanced!
>
> Kind Regards,
>
> Abdur-Rahmaan Janhangeer
> about  | blog
> 
> github 
> Mauritius
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tuple unpacking inside lambda expressions

2022-04-20 Thread Sam Ezeh
I went back to the code recently and I remembered what the problem was.

I was using multiprocessing.Pool.pmap which takes a callable (the
lambda here) so I wasn't able to use comprehensions or starmap

Is there anything for situations like these?

Kind Regards,
Sam Ezeh

On Sat, 16 Apr 2022 at 22:36, Sam Ezeh  wrote:
>
> Two questions here.
>
> Firstly, does anybody know of existing discussions (e.g. on here or on
> python-ideas) relating to unpacking inside lambda expressions?
>
> I found myself wanting to write the following.
>
> ```
> map(
> lambda (module, data): result.process(module, data),
>  jobs
> )
> ```
> However, it's of course not legal Python syntax.
>
> The following were potential options but I felt they removed some of
> the meaning from the code, making it less understandable for other
> people.
>
> ```
> map(
> lambda job: result.process(job[0], job[1]),
>  jobs
> )
> ```
>
> ```
> map(
> lambda job: result.process(*job),
> jobs
> )
> ```
>
> Secondly, for situations like these, do you have any go-to methods of
> rewriting these while maintaining clarity?
>
> Kind Regards,
> Sam Ezeh
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tuple unpacking inside lambda expressions

2022-04-20 Thread Sam Ezeh
This also works great!

Kind Regards,
Sam Ezeh

On Tue, 19 Apr 2022 at 12:03, Antoon Pardon  wrote:
>
> Op 16/04/2022 om 23:36 schreef Sam Ezeh:
> > Two questions here.
> >
> > Firstly, does anybody know of existing discussions (e.g. on here or on
> > python-ideas) relating to unpacking inside lambda expressions?
> >
> > I found myself wanting to write the following.
> >
> > ```
> > map(
> >  lambda (module, data): result.process(module, data),
> >   jobs
> > )
> > ```
> > However, it's of course not legal Python syntax.
>
> Why not write:
>
> itertools.starmap(result.process, jobs)
>
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Enums and nested classes

2022-04-20 Thread Sam Ezeh
Hello everyone,

Has anyone here used or attempted to use a nested class inside an enum?

If so, how did you find it? (what did you expect to happen and did
your expectations align with resulting behaviour etc.)

Here are two examples describing the situation I'm talking about

```
class Outer(Enum):
a = 1
b = 2
class Inner(Enum):
foo = 10
bar = 11
```

```
class Outer(Enum):
a = 1
b = 2
class Inner:
c = None
def __init__(self):

```

Kind Regards,
Sam Ezeh
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Proposal: Syntax for attribute initialisation in __init__ methods

2022-04-20 Thread Sam Ezeh
I'll see if I can find out how positional only and keyword only
arguments are used in __init__ methods in the wild and I'll see if
there have been any other discussions talking about what this approach
could offer.

On Sun, 17 Apr 2022 at 02:54, dn  wrote:
>
> On 17/04/2022 09.20, Sam Ezeh wrote:
> >> Perhaps I'm missing the point, but what functionality or advantage(s)
> >> does this give, over data-classes?
> >
> > One advantage is maintaining control over the __init__ function without
> > having to write extra code to do so. In the linked discussion from
> > python-ideas, it was mentioned that keyword-only and positional-only
> > arguments can't be used with dataclasses [1].
> >
> >> Maybe Dataclasses are not being used as much as one might hope, but they
> >> are relatively new, and many Python-Masters simply carry-on constructing
> >> classes the way they have for years...
> >
> > I think one concern I have is that even if this is useful, it might
> > still fall to the same fate.
>
>
> Don't be discouraged by that - and that thread was not the first of such
> discussions! The way Python is being applied is continually changing...
>
> I'm not sure about the criticism of dataclasses though. Starting with
> 'explicit over implicit', once a parameter-list is more than two or
> three long, shouldn't we be using 'labels' in order to avoid (potential)
> confusion, ie keyword-parameters?
>
> This removes the order/sequence of arguments from the list of potential
> problems/gotchas one can fall into!
>
> In which case, I'm wondering just how often the criticism applies 'in
> real life'?
>
> So, now the question becomes: what are the cases/examples which
> require/desire improvement over the 'traditional' __init__ of
> attributes, and facilities offered through dataclasses?
> --
> Regards,
> =dn
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tuple unpacking inside lambda expressions

2022-04-16 Thread Sam Ezeh
> In general, if you're using map() with a lambda function, it's often
simpler to switch to a comprehension.

Oh, of course, completely went past my head.

> [result.process(module, data) for module, data in jobs]

And this works great, thanks!

On Sat, 16 Apr 2022 at 22:42, Chris Angelico  wrote:
>
> On Sun, 17 Apr 2022 at 07:37, Sam Ezeh  wrote:
> >
> > Two questions here.
> >
> > Firstly, does anybody know of existing discussions (e.g. on here or on
> > python-ideas) relating to unpacking inside lambda expressions?
> >
> > I found myself wanting to write the following.
> >
> > ```
> > map(
> > lambda (module, data): result.process(module, data),
> >  jobs
> > )
> > ```
> > However, it's of course not legal Python syntax.
>
> What about:
>
> [result.process(module, data) for module, data in jobs]
>
> (or with () instead of [] around the outside if you want a generator)?
>
> In general, if you're using map() with a lambda function, it's often
> simpler to switch to a comprehension.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Fwd: Proposal: Syntax for attribute initialisation in __init__ methods

2022-04-16 Thread Sam Ezeh
I've just seen Pablo's very recent post on python-ideas so I thought
I'd link it here. [1]

[1]: 
https://mail.python.org/archives/list/python-id...@python.org/message/SCXHEWCHBJN3A7DPGGPPFLSTMBLLAOTX/

Kind Regards,
Sam Ezeh


On Fri, 15 Apr 2022 at 22:57, Ethan Furman  wrote:
>
> On 4/15/22 04:19, Sam Ezeh wrote:
> > Elsewhere, the idea of supporting new syntax to automatically initialise
> > attributes provided as arguments to __init__ methods was raised.
>
> [...]
>
> Good post!  You'll want to send this to python-ideas at some point (that's 
> where most new python features are
> discussed).  This particular desire has come up in the past, so you'll need 
> to do some more research (i.e. find the
> previous threads on python-ideas) so you can answer objections already 
> raised, or find new data supporting/refuting
> previous arguments.
>
> --
> ~Ethan~
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Fwd: Proposal: Syntax for attribute initialisation in __init__ methods

2022-04-16 Thread Sam Ezeh
> Perhaps I'm missing the point, but what functionality or advantage(s)
> does this give, over data-classes?

One advantage is maintaining control over the __init__ function
without having to write extra code to do so. In the linked discussion
from python-ideas, it was mentioned that keyword-only and
positional-only arguments can't be used with dataclasses [1].

> Maybe Dataclasses are not being used as much as one might hope, but they
> are relatively new, and many Python-Masters simply carry-on constructing
> classes the way they have for years...

I think one concern I have is that even if this is useful, it might
still fall to the same fate.

[1]: 
https://mail.python.org/archives/list/python-id...@python.org/message/SCTXSEKOWDRDGVXXOEB7JUC6WE7XKGMO/


On Fri, 15 Apr 2022 at 22:30, dn  wrote:
>
> On 15/04/2022 23.19, Sam Ezeh wrote:
> ...
>
> Kudos for doing the research!
>
>
> > Some related implementations are attrs, dataclasses and the use of a
> > decorator. And there's potentially a point to be raised that the results
> > from the first query indicate that the @dataclasse decorator is not being
> > used enough. One advantage this proposal offers is control over the
> > arguments that the __init__ function takes.
> >
> > A downside to using a decorator is that it might become difficult to accept
> > arguments that don't need to be assigned to anything.
> >
> > I gave the example of the following code (unlike the above, this is not
> > taken from existing python source code). In this example, a decorator can't
> > assign all of the arguments to attributes or else it would produce code
> > that does something different.
> ...
>
>
> I will support anything which reduces 'boiler-plate' or 'make busy' work!
>
> Perhaps I'm missing the point, but what functionality or advantage(s)
> does this give, over data-classes?
>
> Maybe Dataclasses are not being used as much as one might hope, but they
> are relatively new, and many Python-Masters simply carry-on constructing
> classes the way they have for years...
>
> If data-classes give the impression of being 'syntactic sugar', there's
> no particular need to use them - and certainly no rule or demand.
>
> There are constructs where one might find it easier not to use them.
>
> @dataclass does allow init=False.
>
> There is an argument which says that all data-attributes should be
> 'created' inside an __init__() or __post_init__(), rather than
> 'somewhere', 'later'.
> --
> Regards,
> =dn
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Tuple unpacking inside lambda expressions

2022-04-16 Thread Sam Ezeh
Two questions here.

Firstly, does anybody know of existing discussions (e.g. on here or on
python-ideas) relating to unpacking inside lambda expressions?

I found myself wanting to write the following.

```
map(
lambda (module, data): result.process(module, data),
 jobs
)
```
However, it's of course not legal Python syntax.

The following were potential options but I felt they removed some of
the meaning from the code, making it less understandable for other
people.

```
map(
lambda job: result.process(job[0], job[1]),
 jobs
)
```

```
map(
lambda job: result.process(*job),
jobs
)
```

Secondly, for situations like these, do you have any go-to methods of
rewriting these while maintaining clarity?

Kind Regards,
Sam Ezeh
-- 
https://mail.python.org/mailman/listinfo/python-list


Proposal: Syntax for attribute initialisation in __init__ methods

2022-04-15 Thread Sam Ezeh
f when an __init__ method only
contains arguments that will become attributes. From the cryptography
library, there's the following example.

```
class _DeprecatedValue:
def __init__(self, value: object, message: str, warning_class):
self.value = value
self.message = message
self.warning_class = warning_class
```

With the new syntax, this would become the following

```
class _DeprecatedValue:
def __init__(self, @value: object, @message: str, @warning_class):
pass
```

The empty __init__ method seems unnecessary so perhaps it could be reduced
further to the following

```
class _DeprecatedValue:
@value: object
@message: str
@warning_class
```

With regards to implementation details, there are questions about the order
of execution, right now it seems to make sense to me that attributes should
be assigned to prevent them from being overridden by any calls to super()
for code similar to that in the numpy example. Another question could be
what happens if the syntax is used outside of an __init__ method. Right
now, it seems to me that this could be ok and the code could run the same
as it would inside the __init__ method. There is also the question of what
happens if the syntax is used inside a function that isn't defined in a
class, and perhaps this usage should be rejected. As another edge case,
there's the question of what would happen if this syntax is used on
functions labelled with the @staticmethod decorator. Type hinting will also
have to be dealt with.

With all of this in mind, I'd like to hear what other people think about
this proposal.

To perform the queries I created a tool called presearch which others might
find useful. I found it quite fun to make however it's only been in
existence for 2 days so there currently isn't any documentation and it's
lacking in several areas.
The source code can be found here: https://github.com/dignissimus/presearch

Kind Regards,
Sam Ezeh
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Functionality like local static in C

2022-04-14 Thread Sam Ezeh
I've seen people use function attributes for this.
```
Python 3.10.2 (main, Jan 15 2022, 19:56:27) [GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> def function():
... print(function.variable)
... function.variable += 1
...
>>> function.variable = 1
>>> function()
1
>>> function()
2
>>>
```

If necessary, the variable can be initialised inside the function too.

Kind Regards,
Sam Ezeh

On Thu, 14 Apr 2022 at 16:36, Sam Ezeh  wrote:
>
> I've seen people use function attributes for this.
> ```
> Python 3.10.2 (main, Jan 15 2022, 19:56:27) [GCC 11.1.0] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> def function():
> ... print(function.variable)
> ... function.variable += 1
> ...
> >>> function.variable = 1
> >>> function()
> 1
> >>> function()
> 2
> >>>
> ```
>
> If necessary, the variable can be initialised inside the function too.
>
> Kind Regards,
> Sam Ezeh
>
>
> On Thu, 14 Apr 2022 at 16:26, Cecil Westerhof via Python-list
>  wrote:
> >
> > In C when you declare a variable static in a function, the variable
> > retains its value between function calls.
> > The first time the function is called it has the default value (0 for
> > an int).
> > But when the function changes the value in a call (for example to 43),
> > the next time the function is called the variable does not have the
> > default value, but the value it had when the function returned.
> > Does python has something like that?
> >
> > --
> > Cecil Westerhof
> > Senior Software Engineer
> > LinkedIn: http://www.linkedin.com/in/cecilwesterhof
> > --
> > https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list