python / cpython

The Python programming language
https://www.python.org
Other
66.34k stars 31.63k forks source link

splitext and leading point of hidden files #36344

Closed 59170980-d00c-4fc4-96f3-6235e1592bf3 closed 23 years ago

59170980-d00c-4fc4-96f3-6235e1592bf3 commented 23 years ago
BPO 536120
Nosy @tim-one, @loewis
Files
  • posixpath.dif: diff for posixpath.splitext
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields: ```python assignee = None closed_at = created_at = labels = ['library'] title = 'splitext and leading point of hidden files' updated_at = user = 'https://bugs.python.org/skeim' ``` bugs.python.org fields: ```python activity = actor = 'tim.peters' assignee = 'none' closed = True closed_date = None closer = None components = ['Library (Lib)'] creation = creator = 's_keim' dependencies = [] files = ['4085'] hgrepos = [] issue_num = 536120 keywords = ['patch'] message_count = 7.0 messages = ['39363', '39364', '39365', '39366', '39367', '39368', '39369'] nosy_count = 3.0 nosy_names = ['tim.peters', 'loewis', 's_keim'] pr_nums = [] priority = 'normal' resolution = 'rejected' stage = None status = 'closed' superseder = None type = None url = 'https://bugs.python.org/issue536120' versions = ['Python 2.3'] ```

    59170980-d00c-4fc4-96f3-6235e1592bf3 commented 23 years ago

    The posixpath.splitext function doesn't do the right thing with leading point of hidden files. For sample: splitext('.emacs')==('','.emacs'). The patch is intended to leave the leading point as part of the name.

    Existing code will possibly break, so this patch is probably quite controversial. If the behaviour change is rejected, the patch could be modified to improve performances without behaviour changes.

    tim-one commented 23 years ago

    Logged In: YES user_id=31435

    I expect this change has scant chance of being accepted.

    The idea that leading dot means "hidden" is an arbitrary convention of the ls utility, and your desire to call a .name file "pure name" instead of "pure extension" seems
    arbitrary too. The behavior of splitext is perfectly predictable as-is across platforms now (note the implication: if you intend to change the semantics for posixpath, you'll also have to sell that it should be changed for dospath.py, ntpath.py, macpath.py, os2emxpath.py, and riscospath.py).

    Note that the patched function splits, e.g.,

    '/usr/local/tim.one/seven'

    into

    '/usr/local/tim'

    and

    '.one/seven'

    I assume that's not the result you intended.

    59170980-d00c-4fc4-96f3-6235e1592bf3 commented 23 years ago

    Logged In: YES user_id=498191

    oop's your right.

    I thought that the for loop was only a reminiscence of the time when the string module was coded in python. In fact it seems that things are a little more complex than I intended :(

    But if we replace: if i\<1 or p[i-1]=='/': by: if i\<0 or i\<p.rfind('/'):

    We should win in performances without breaking current behavior, or am I missing something else?

    About the behavior change proposal: My opinion is that the 'leading dot means hidden' is a quite strong convention in unixes (and no, not only for the ls utility). But this is not true on other os (at least on Mac and Windows). So, if cross platform predictability is important (and I think it is), I agree it is probably better to not try to change this.

    59170980-d00c-4fc4-96f3-6235e1592bf3 commented 23 years ago

    Logged In: YES user_id=498191

    oop's your right.

    I thought that the for loop was only a reminiscence of the time when the string module was coded in python. In fact it seems that things are a little more complex than I intended :(

    But if we replace: if i\<1 or p[i-1]=='/': by: if i\<0 or i\<p.rfind('/'):

    We should win in performances without breaking current behavior, or am I missing something else?

    About the behavior change proposal: My opinion is that the 'leading dot means hidden' is a quite strong convention in unixes (and no, not only for the ls utility). But this is not true on other os (at least on Mac and Windows). So, if cross platform predictability is important (and I think it is), I agree it is probably better to not try to change this.

    61337411-43fc-4a9c-b8d5-4060aede66d0 commented 23 years ago

    Logged In: YES user_id=21627

    I also dislike this patch. The current behaviour completely matches the documented behaviour; changing it might break existing applications. If you need a different behaviour, write a different function.

    59170980-d00c-4fc4-96f3-6235e1592bf3 commented 23 years ago

    Logged In: YES user_id=498191

    After a good night, I understand that this patch would break too much code and be very confusing. So I suggest to close it as rejected.

    tim-one commented 23 years ago

    Logged In: YES user_id=31435

    BTW, if it *weren't* for the code breakage, I'd be in favor of doing this. A quick survey at work yesterday showed that most of those who expressed a preference were at least mildly in favor of calling .emacs "pure name, no extension". While the docstring is clear that it's treated as "pure extension", and that's what the code does too, the Library Manual docs are consistent with either notion.