Re: Discuss: use slots for all classes in leoNodes.py

2021-06-30 Thread Edward K. Ream
On Wed, Jun 30, 2021 at 3:38 AM Alexey Tikhonov 
wrote:

> Leo (devel) starts regularly terminating when I use quicksearch window. It
> says:

...
pc.matchiter = t2
AttributeError: 'Position' object has no attribute 'matchiter'

Do you think it can be related to that change?
>

Yes. Almost for sure.

I have just created #2022
. I'll fix it
immediately.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/CAMF8tS1fFC004poiFSJ9bppw_W%3D6Q0Y5ZFGwAe2VW3dQrdUJ_A%40mail.gmail.com.


Re: Discuss: use slots for all classes in leoNodes.py

2021-06-30 Thread Alexey Tikhonov
Leo (devel) starts regularly terminating when I use quicksearch window. It 
says:

Traceback (most recent call last):
  File 
"C:\Users\atikhonov2\Workarea\leo-editor\repo\leo\plugins\quicksearch.py", 
line 333, in returnPressed
self.scon.doSearch(t)
  File 
"C:\Users\atikhonov2\Workarea\leo-editor\repo\leo\plugins\quicksearch.py", 
line 598, in doSearch
bm = self.find_b(bpat, bNodes, flags)
  File 
"C:\Users\atikhonov2\Workarea\leo-editor\repo\leo\plugins\quicksearch.py", 
line 686, in find_b
pc.matchiter = t2
AttributeError: 'Position' object has no attribute 'matchiter'

Do you think it can be related to that change?

Alexey
On Monday, June 28, 2021 at 10:28:35 PM UTC+7 Edward K. Ream wrote:

> On Thursday, June 24, 2021 at 12:48:33 PM UTC-5 Edward K. Ream wrote:
>
>> This is PR #2003  
>> and issue #2004 .
>>
>> Unless I hear compelling arguments against, I plan to "freeze" all the 
>> classes in leoNodes.py (Position, VNode, NodeIndices and PosList classes) 
>> by defining a __slot__ attribute 
>> for each class.
>>
>
> Adding slots prevents plugins from directly injecting attributes into 
> Position objects.
>
> #2015  suggests 
> adding p.pluginDict as a workaround.
>
> All comments welcome.
>
> Edward
>

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/bb57dd5d-b967-49cc-8915-1af2ce0085fan%40googlegroups.com.


Re: Discuss: use slots for all classes in leoNodes.py

2021-06-28 Thread Edward K. Ream


On Thursday, June 24, 2021 at 12:48:33 PM UTC-5 Edward K. Ream wrote:

> This is PR #2003  and 
> issue #2004 .
>
> Unless I hear compelling arguments against, I plan to "freeze" all the 
> classes in leoNodes.py (Position, VNode, NodeIndices and PosList classes) 
> by defining a __slot__ attribute 
> for each class.
>

Adding slots prevents plugins from directly injecting attributes into 
Position objects.

#2015  suggests 
adding p.pluginDict as a workaround.

All comments welcome.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/d34799f7-f59f-47a9-84ac-28b0d43275edn%40googlegroups.com.


Re: Discuss: use slots for all classes in leoNodes.py

2021-06-27 Thread Edward K. Ream


On Thursday, June 24, 2021 at 12:48:33 PM UTC-5 Edward K. Ream wrote:

> This is PR #2003  and 
> issue #2004 .
>
> Unless I hear compelling arguments against, I plan to "freeze" all the 
> classes in leoNodes.py (Position, VNode, NodeIndices and PosList classes) 
> by defining a __slot__ attribute 
> for each 
> class.  It is straightforward to do this.  See PR #2003.
>

The new code has now been merged into devel.

In the *extremely* unlikely event that slots ever cause problem, removing 
them from a class is simply a matter of eliminating the class's __slot__ 
statement.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/8120c5c3-fd4a-4812-b363-3f0c2f649eb2n%40googlegroups.com.


Re: Discuss: use slots for all classes in leoNodes.py

2021-06-24 Thread Edward K. Ream
On Thursday, June 24, 2021 at 3:09:29 PM UTC-5 Edward K. Ream wrote:

> The Position class should never ever need any kind of extension, so 
adding slots is protection, pure and simple.

Slots also reduce the stress on python's GC (garbage collector) and slots 
also reduce access times to ivars. However, Leo already is careful not to 
allocate positions needlessly, so the resulting performance improvements 
are of little practical importance.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/0e279fbb-01bd-4531-b862-a16da963a452n%40googlegroups.com.


Re: Discuss: use slots for all classes in leoNodes.py

2021-06-24 Thread Edward K. Ream
On Thu, Jun 24, 2021 at 2:12 PM tbp1...@gmail.com 
wrote:

> Would you give an example of how these slots would be used, please?
>

Good question. Typical Leo users will not notice any change whatsoever.

The only sense in which slots are "used" is that slots prevent scripts (or
any part of Leo itself) from "injecting" new ivars into the classes. This
restriction allows pylint  and mypy to detect misspellings and other
serious errors.

The VNode class already has an extension mechanism, namely
v.unknownAttributes. That should be plenty good enough.

The Position class should never ever need any kind of extension, so adding
slots is protection, pure and simple.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/CAMF8tS3%3D-JFGXZ29TNeNAhcj4v9xdzW0PTxe%3DXK1238Zv0M8rw%40mail.gmail.com.


Re: Discuss: use slots for all classes in leoNodes.py

2021-06-24 Thread tbp1...@gmail.com
Would you give an example of how these slots would be used, please?

On Thursday, June 24, 2021 at 1:48:33 PM UTC-4 Edward K. Ream wrote:

> This is PR #2003  and 
> issue #2004 .
>
> Unless I hear compelling arguments against, I plan to "freeze" all the 
> classes in leoNodes.py (Position, VNode, NodeIndices and PosList classes) 
> by defining a __slot__ attribute 
> for each 
> class.  It is straightforward to do this.  See PR #2003.
>
> *Rationale*
>
> mypy recently discovered a bug arising from a misspelling of an ivar of 
> the VNode class. This freaked me out. Without slots, pylint does not (and 
> can not) detect such errors because there is no of knowing whether the code 
> actually intended to inject a new ivar.
>
> Without slots, Leo's most important data classes can neither be checked 
> nor protected properly! 
>
> *Summary*
>
> Imo, using slots in leoNodes.py is overdue. I know of no drawbacks to 
> doing so.
>
> Slots have at least these advantages:
>
> - Slots help pylint and mypy check code.
> - Slots reduce the memory footprint of positions and vnodes.
> - Slots prevent unwanted alterations of Leo's most important classes. 
>
> The work is in the ekr-slots branch.  I'll wait for a few days for your 
> comments.
>
> Edward
>

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/328aae28-2b4a-4cf4-bc16-aeab3178ab9en%40googlegroups.com.


Discuss: use slots for all classes in leoNodes.py

2021-06-24 Thread Edward K. Ream
This is PR #2003  and 
issue #2004 .

Unless I hear compelling arguments against, I plan to "freeze" all the 
classes in leoNodes.py (Position, VNode, NodeIndices and PosList classes) 
by defining a __slot__ attribute 
for each class.  
It is straightforward to do this.  See PR #2003.

*Rationale*

mypy recently discovered a bug arising from a misspelling of an ivar of the 
VNode class. This freaked me out. Without slots, pylint does not (and can 
not) detect such errors because there is no of knowing whether the code 
actually intended to inject a new ivar.

Without slots, Leo's most important data classes can neither be checked nor 
protected properly! 

*Summary*

Imo, using slots in leoNodes.py is overdue. I know of no drawbacks to doing 
so.

Slots have at least these advantages:

- Slots help pylint and mypy check code.
- Slots reduce the memory footprint of positions and vnodes.
- Slots prevent unwanted alterations of Leo's most important classes. 

The work is in the ekr-slots branch.  I'll wait for a few days for your 
comments.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/8b79e17d-03c4-447f-bf2b-5b01a829299fn%40googlegroups.com.