[issue44069] pathlib.Path.glob's generator is not a real generator

2021-05-07 Thread Elijah Rippeth


New submission from Elijah Rippeth :

I have a directory with hundreds of thousands of text files. I wanted to 
explore one file, so I wrote the following code expecting it to happen 
basically instantaneously because of how generators work:

```python
from pathlib import Path

base_dir = Path("/path/to/lotta/files/")
files = base_dir.glob("*.txt")# return immediately
first_file = next(files)  # doesn't return immediately
```

to my surprise, this took a long time to finish since `next` on a generator 
should be O(1).

A colleague pointed me to the following code: 
https://github.com/python/cpython/blob/adcd2205565f91c6719f4141ab4e1da6d7086126/Lib/pathlib.py#L431

I assume calling this list is to "freeze" a potentially changing directory 
since `scandir` relies on `os.stat`, but this causes a huge penalty and makes 
the generator return-type a bit disingenuous. In any case, I think this is bug 
worthy in someo sense.

--
components: IO
messages: 393190
nosy: Elijah Rippeth
priority: normal
severity: normal
status: open
title: pathlib.Path.glob's generator is not a real generator
type: performance
versions: Python 3.6

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



[issue44069] pathlib.Path.glob's generator is not a real generator

2021-05-11 Thread Elijah Rippeth


Change by Elijah Rippeth :


--
versions: +Python 3.10, Python 3.11, Python 3.7, Python 3.8, Python 3.9

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



[issue40749] Consider adding decorator for required inner class

2020-05-23 Thread Elijah Rippeth


New submission from Elijah Rippeth :

Sometimes it's desirable to couple classes together by nesting. Currently 
there's no way to signal to an interface implementer that an inner class is a 
required attribute to be implemented. 

I propose a decorator for `abstractnestedclass` to fill this gap. A simple 
example use-case is outlined below:

```
from abc import ABCMeta, abstractnestedclass

class BaseComponent(metaclass=ABCMeta):
@abstractnestedclass
class Config:
pass

class MissingNestedComponent(BaseComponent):
# This will raise when constructed because 
# BaseComponent.Config is not implemented
pass

class NonraisingComponent(BaseComponent):
# This will be constructable
class NonraisingComponentConfig(BaseComponent.Config):
pass
pass
```

--
components: Library (Lib)
messages: 369756
nosy: Elijah Rippeth
priority: normal
severity: normal
status: open
title: Consider adding decorator for required inner class
type: enhancement

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