Working with paths

2023-07-16 Thread Peter Slížik via Python-list
Hello, I finally had a look at the pathlib module. (Should have done it long ago, but anyway...). Having in mind the replies from my older thread (File system path annotations), what is the best way to support all possible path types? def doit(path: str | bytes | os.PathLike): match path: case st

Best practices for using super()

2023-07-04 Thread Peter Slížik via Python-list
As a follow-up to my yesterday's question - are there any recommendations on the usage of super()? It's clear that super() can be used to invoke parent's: - instance methods - static methods - constants ("static" attributes in the parent class, e.g. super().NUMBER). This all works, but are the

Re: Multiple inheritance and a broken super() chain

2023-07-04 Thread Peter Slížik via Python-list
> > Also, you might find that because of the MRO, super() in your Bottom > class would actually give you what you want. > I knew this, but I wanted to save myself some refactoring, as the legacy code used different signatures for Left.__init__() and Right.__init__(). I realized the formatting of

Multiple inheritance and a broken super() chain

2023-07-03 Thread Peter Slížik via Python-list
Hello. The legacy code I'm working with uses a classic diamond inheritance. Let me call the classes *Top*, *Left*, *Right*, and *Bottom*. This is a trivial textbook example. The classes were written in the pre-super() era, so all of them initialized their parents and Bottom initialized both Left a

Re: File system path annotations

2023-06-19 Thread Peter Slížik via Python-list
Thank you, Roel. You've answered all my questions. > [PEP 519]: ...as that can be represented with typing.Union[str, bytes, os.PathLike] easily enough and the hope is users > will slowly gravitate to path objects only. I read a lot on Python and, frankly, I don't see this happening. People on the

File system path annotations

2023-06-19 Thread Peter Slížik via Python-list
Hello, what is the preferred way of annotating file system paths? This StackOverflow answer (and a few others) recommend using the str | os.PathLike union. However, byte arrays can be used as paths too, and including them would make the annotation