[issue24132] Direct sub-classing of pathlib.Path

2018-03-28 Thread Christophe BAL

Christophe BAL <projet...@gmail.com> added the comment:

Hello.

What about AbstractPath instead of _PurePath ?

Le 28/03/2018 à 02:30, qb-cea a écrit :
> qb-cea <quentin.bou...@cea.fr> added the comment:
>
> Hi all,
>
> I made a pull request proposing a fix for this issue. There is still quite a 
> lot to be done:
>   - I exposed some variables (and probably methods too) that used to be 
> hidden;
>   - I did not update the documentation;
>   - I did not add a proper test.
>
> I will try to fix those by the end of the week.
>
> The patch mainly consists of two things:
>   - having Path (resp. PurePath) be a variable pointing at either 
> (Pure)PosixPath or (Pure)WindowsPath, depending on the platform (like Kevin 
> Norris suggested);
>   - introducing two new abstract classes _PurePath and ConcretePath from 
> which PurePosixPath, PureWindowsPath and PosixPath, WindowsPath classes 
> inherit;
>   - removing the _Flavor classes, and redistributing their method to 
> platform-specific classes.
>
> Ideally I would like _PurePath to become a public class, but I could not come 
> up with a proper name. Any feedback is more than welcome =]
>
> --
>
> ___
> Python tracker <rep...@bugs.python.org>
> <https://bugs.python.org/issue24132>
> ___

--

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



[issue24132] Direct sub-classing of pathlib.Path

2017-11-08 Thread Christophe BAL

Christophe BAL <projet...@gmail.com> added the comment:

Mistyping : /search for class PPath/ with two P.

Le 08/11/2017 à 13:59, Christophe BAL a écrit :
> Christophe BAL <projet...@gmail.com> added the comment:
>
> For the moment, you can take a look at this little script that acheives
> subclassing of Path :
> https://github.com/bc-python/mistool/blob/master/mistool/os_use.py
> (search for class Path).
>
> Le 08/11/2017 à 09:55, Paul Moore a écrit :
>> Paul Moore <p.f.mo...@gmail.com> added the comment:
>>
>> @elguavas the problem is, no-one has proposed a patch. There's not likely to 
>> be much movement on this until someone provides one.
>>
>> --
>>
>> ___
>> Python tracker <rep...@bugs.python.org>
>> <https://bugs.python.org/issue24132>
>> ___
> --
>
> ___
> Python tracker <rep...@bugs.python.org>
> <https://bugs.python.org/issue24132>
> ___

--

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



[issue24132] Direct sub-classing of pathlib.Path

2017-11-08 Thread Christophe BAL

Christophe BAL <projet...@gmail.com> added the comment:

For the moment, you can take a look at this little script that acheives 
subclassing of Path : 
https://github.com/bc-python/mistool/blob/master/mistool/os_use.py 
(search for class Path).

Le 08/11/2017 à 09:55, Paul Moore a écrit :
> Paul Moore <p.f.mo...@gmail.com> added the comment:
>
> @elguavas the problem is, no-one has proposed a patch. There's not likely to 
> be much movement on this until someone provides one.
>
> --
>
> ___
> Python tracker <rep...@bugs.python.org>
> <https://bugs.python.org/issue24132>
> ___

--

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



[issue24132] Direct sub-classing of pathlib.Path

2015-05-06 Thread Christophe BAL

Changes by Christophe BAL projet...@gmail.com:


--
title: Direct sub-classing of pathless.Path - Direct sub-classing of 
pathlib.Path

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



[issue24132] Direct sub-classing of pathlib.Path

2015-05-06 Thread Christophe BAL

Christophe BAL added the comment:

Hello.

I will give a real example in 5 hours after my job. I will try tomorrow a
solution to ease the subclassing using another dedicazted class PathPlus,
sorry for the name. The idea would be to use this new class for
customization, and also to define WindowsPath and PosixPath sub-classing
this new class. By default PathPlus would be an empty class. I do not know
if this works well. Maybe my idea is a bad one.

*Christophe BAL*
*Enseignant de mathématiques en Lycée **et développeur Python amateur*
*---*
*French math teacher in a Lycée **and **Python **amateur developer*

2015-05-06 13:05 GMT+02:00 Antoine Pitrou rep...@bugs.python.org:


 Antoine Pitrou added the comment:

 The Path classes were not designed to be subclassable by the user.
 I'm not against making subclassing easier, but someone will have to
 propose a viable approach for that.

 --
 versions: +Python 3.5 -Python 3.4

 ___
 Python tracker rep...@bugs.python.org
 http://bugs.python.org/issue24132
 ___


--

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



[issue24132] Direct sub-classing of pathlib.Path

2015-05-06 Thread Christophe BAL

Christophe BAL added the comment:

Here are for example two extra methods that I have implemented.

def __sub__(cls, path):

This magic method allows to use ``onepath - anotherpath`` instead of the
long
version ``onepath.relative_to(anotherpath)`` given by ``pathlib.Path``.

return cls.relative_to(path)

def _ppath_common_with(cls, paths):

This method returns the path of the smaller common folder of the current
path
and at least one paths.

python::
from mistool import os_use

path   = os_use.PPath(/Users/projects/source/doc)
path_1 = os_use.PPath(/Users/projects/README)
path_2 = os_use.PPath(/Users/projects/source/misTool/os_use.py)

print(path.common_with((path_1, path_2)))

if not isinstance(paths, (list, tuple)):
paths = [paths]

commonparts = list(cls.parts)

for onepath in paths:
i = 0

for common, actual in zip(commonparts, onepath.parts):
if common == actual:
i += 1
else:
break

commonparts = commonparts[:i]

if not commonparts:
break

commonpath = pathlib.Path()

for part in commonparts:
commonpath /= part

return commonpath

*Christophe BAL*
*Enseignant de mathématiques en Lycée **et développeur Python amateur*
*---*
*French math teacher in a Lycée **and **Python **amateur developer*

2015-05-06 14:13 GMT+02:00 Christophe BAL rep...@bugs.python.org:


 Christophe BAL added the comment:

 Hello.

 I will give a real example in 5 hours after my job. I will try tomorrow a
 solution to ease the subclassing using another dedicazted class PathPlus,
 sorry for the name. The idea would be to use this new class for
 customization, and also to define WindowsPath and PosixPath sub-classing
 this new class. By default PathPlus would be an empty class. I do not know
 if this works well. Maybe my idea is a bad one.

 *Christophe BAL*
 *Enseignant de mathématiques en Lycée **et développeur Python amateur*
 *---*
 *French math teacher in a Lycée **and **Python **amateur developer*

 2015-05-06 13:05 GMT+02:00 Antoine Pitrou rep...@bugs.python.org:

 
  Antoine Pitrou added the comment:
 
  The Path classes were not designed to be subclassable by the user.
  I'm not against making subclassing easier, but someone will have to
  propose a viable approach for that.
 
  --
  versions: +Python 3.5 -Python 3.4
 
  ___
  Python tracker rep...@bugs.python.org
  http://bugs.python.org/issue24132
  ___
 

 --

 ___
 Python tracker rep...@bugs.python.org
 http://bugs.python.org/issue24132
 ___


--

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



[issue24132] Direct sub-classing of pathlib.Path

2015-05-06 Thread Christophe BAL

Christophe BAL added the comment:

Are you the author of path lib ?

*Christophe BAL*
*Enseignant de mathématiques en Lycée **et développeur Python amateur*
*---*
*French math teacher in a Lycée **and **Python **amateur developer*

2015-05-06 21:01 GMT+02:00 Paul Moore rep...@bugs.python.org:


 Paul Moore added the comment:

 I have no problem with that - it's a style choice certainly.

 As I said, I'd like to see simpler subclassing of pathlib objects. I just
 think it'll be quite hard to do (given the complexities of classes for
 Windows/Unix as well as pure and concrete paths). So if it's just about
 examples like this, I personally would take the easier route and just go
 with standalone functions. If someone else felt strongly enough to design
 and implement a subclassing solution, that's fine though.

 --

 ___
 Python tracker rep...@bugs.python.org
 http://bugs.python.org/issue24132
 ___


--

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



[issue24132] Direct sub-classing of pathlib.Path

2015-05-06 Thread Christophe BAL

Christophe BAL added the comment:

I don't agree with you. I prefer to add new functionalities to the paths I
use. This is the power of OOP. It is easier and cleaner to use
*mypath.common_with(otherpath)*  than  *common_with(**mypath, **other path)*
.

Python is highly OOP, so you can't say *don't use subclassing in your
case*. As a user, I should have the possibility to use the method I want.

Another example is the use of  *onepath - anotherpath*  instead of
*onepath.relative_to(**another path)* . That's the power of the magic
method to add this kind of feature.

*Christophe BAL*
*Enseignant de mathématiques en Lycée **et développeur Python amateur*
*---*
*French math teacher in a Lycée **and **Python **amateur developer*

2015-05-06 20:21 GMT+02:00 Paul Moore rep...@bugs.python.org:


 Paul Moore added the comment:

 For that type of function, I'd suggest you use a standalone function
 rather than subclassing and methods or operator overloading. You don't gain
 enough to be worth the complexity of having to subclass path objects. And
 duck typing means that your function works for any subclass of (Pure)Path
 without change.

 --

 ___
 Python tracker rep...@bugs.python.org
 http://bugs.python.org/issue24132
 ___


--

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



[issue24132] Direct sub-classing of pathlib.Path

2015-05-06 Thread Christophe BAL

Christophe BAL added the comment:

OK.
I will try to find a way to achieve an easier and cleaner way to sub class
pathlib.Path and co.

What is the good way to propose a patch ?

*Christophe BAL*
*Enseignant de mathématiques en Lycée **et développeur Python amateur*
*---*
*French math teacher in a Lycée **and **Python **amateur developer*

2015-05-06 21:09 GMT+02:00 Paul Moore rep...@bugs.python.org:


 Paul Moore added the comment:

  Are you the author of path lib ?

 Nope, that's Antoine.

 --

 ___
 Python tracker rep...@bugs.python.org
 http://bugs.python.org/issue24132
 ___


--

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



[issue24132] Direct sub-classing of pathless.Path

2015-05-05 Thread Christophe BAL

New submission from Christophe BAL:

Hello.

I have noticed a problem with the following code.

from pathlib import Path

class PPath(Path):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

test = PPath(dir, test.txt)

This gives the following error message.

 
Traceback (most recent call last):
  File /Users/projetmbc/test.py, line 14, in module
test = PPath(dir, test.txt)
  File /anaconda/lib/python3.4/pathlib.py, line 907, in __new__
self = cls._from_parts(args, init=False)
  File /anaconda/lib/python3.4/pathlib.py, line 589, in _from_parts
drv, root, parts = self._parse_args(args)
  File /anaconda/lib/python3.4/pathlib.py, line 582, in _parse_args
return cls._flavour.parse_parts(parts)
AttributeError: type object 'PPath' has no attribute '_flavour'

This breaks the sub-classing from Python point of view.

There is an ugly hack to sub-class Path but it's a bit unpythonic.

--
messages: 242643
nosy: projetmbc
priority: normal
severity: normal
status: open
title: Direct sub-classing of pathless.Path
type: behavior
versions: Python 3.4

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



[issue24108] fnmatch.translate('*.txt') fails

2015-05-01 Thread Christophe BAL

Christophe BAL added the comment:

Ok.

But in that case, the official documentation should be updated because it
saids that string regex is  *'.*\\.txt\\Z(?ms)'*  and not  *'.*\\.txt$'*.

On the other hand, using this writing seems a bit strange. The 2nd one
should do the job.

*Christophe BAL*
*Enseignant de mathématiques en Lycée **et développeur Python amateur*
*---*
*French math teacher in a Lycée **and **Python **amateur developer*

2015-05-01 21:42 GMT+02:00 Merlijn van Deen rep...@bugs.python.org:


 Merlijn van Deen added the comment:

 As far as I can see, the regex is correct:

 \Z
 Matches only at the end of the string.

 (?iLmsux)
 The group matches the empty string; the letters set the corresponding
 flags: (...)
   - re.M (multi-line),
   - re.S (dot matches all)

 See https://docs.python.org/3.4/library/re.html

 Do you have an example where the regex does not match a file it should
 match (or matches a file it shouldn't)?

 --
 nosy: +valhallasw

 ___
 Python tracker rep...@bugs.python.org
 http://bugs.python.org/issue24108
 ___


--

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



[issue24108] fnmatch.translate('*.txt') fails

2015-05-01 Thread Christophe BAL

New submission from Christophe BAL:

Hello.

I find the following bug on Python 3.4.

 import fnmatch, re
 regex = fnmatch.translate('*.txt')
 regex
'.*\\.txt\\Z(?ms)'

The string regex should be '.*\\.txt$'.

--
components: asyncio
messages: 242346
nosy: gvanrossum, haypo, projetmbc, yselivanov
priority: normal
severity: normal
status: open
title: fnmatch.translate('*.txt') fails
versions: Python 3.4

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



[issue24108] fnmatch.translate('*.txt') fails

2015-05-01 Thread Christophe BAL

Christophe BAL added the comment:

Oups, sorry I want to say that you are totally RIGHT, and I am definitely
WRONG. :-)

--

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



[issue24108] fnmatch.translate('*.txt') fails

2015-05-01 Thread Christophe BAL

Christophe BAL added the comment:

You're totally wrong and I am wrong.

There is still the tiny problem of the documentation.

Thanks for all.

*Christophe BAL*
*Enseignant de mathématiques en Lycée **et développeur Python amateur*
*---*
*French math teacher in a Lycée **and **Python **amateur developer*

2015-05-01 22:16 GMT+02:00 Merlijn van Deen rep...@bugs.python.org:


 Merlijn van Deen added the comment:

 They are subtly different; the new regex also matches filenames with
 newlines, the old one doesn't (see Issue #6665 [1]).

 Patch (although crazily minor) attached. With some fuzz, it applies on
 everything from 2.6..default.

 [1] https://bugs.python.org/issue6665

 --
 assignee:  - docs@python
 components: +Documentation -asyncio
 keywords: +patch
 nosy: +docs@python
 Added file: http://bugs.python.org/file39261/default.diff

 ___
 Python tracker rep...@bugs.python.org
 http://bugs.python.org/issue24108
 ___


--

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