[issue23780] Surprising behaviour when passing list to os.path.join.

2015-05-21 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

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



[issue23780] Surprising behaviour when passing list to os.path.join.

2015-05-19 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 84af71e8c051 by Serhiy Storchaka in branch 'default':
Issue #23780: Improved error message in os.path.join() with single argument.
https://hg.python.org/cpython/rev/84af71e8c051

--
nosy: +python-dev

___
Python tracker 

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



[issue23780] Surprising behaviour when passing list to os.path.join.

2015-05-16 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Oh, sorry, I forget to attach it.

--
Added file: http://bugs.python.org/file39394/join_datatype_check_2.patch

___
Python tracker 

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



[issue23780] Surprising behaviour when passing list to os.path.join.

2015-05-16 Thread Florian Bruhin

Florian Bruhin added the comment:

Serhiy, I don't see a new patch added - did you forget to attach it or am I 
missing something? :)

--

___
Python tracker 

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



[issue23780] Surprising behaviour when passing list to os.path.join.

2015-05-16 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Here is extended patch, with tests.

--
assignee:  -> serhiy.storchaka
stage:  -> patch review
versions:  -Python 3.4

___
Python tracker 

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



[issue23780] Surprising behaviour when passing list to os.path.join.

2015-03-26 Thread R. David Murray

R. David Murray added the comment:

No, I'm not going to write tests...my goal is to commit other people's patches, 
and I haven't even found time for that lately.  And like you, I'm not convinced 
the fix is needed.  There is one argument I can think  of in favor, though: 
currently code that doesn't raise an error on posix will raise an error on 
Windows, and there is some portability value in making this consistent.

(Side note: the fact that join works with things that look enough like strings 
is important, because I'm sure that there are pathlib-like libraries out there 
that pretend to be strings so that they can be used in things like path.join.)

--

___
Python tracker 

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



[issue23780] Surprising behaviour when passing list to os.path.join.

2015-03-26 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Error message for ntpath is improved in 3.5.

>>> import ntpath
>>> ntpath.join([1, 2, 3])
Traceback (most recent call last):
  File "", line 1, in 
  File "/home/serhiy/py/cpython/Lib/ntpath.py", line 111, in join
genericpath._check_arg_types('join', path, *paths)
  File "/home/serhiy/py/cpython/Lib/genericpath.py", line 143, in 
_check_arg_types
(funcname, s.__class__.__name__)) from None
TypeError: join() argument must be str or bytes, not 'list'

I'm not sure that the case of single argument in posixpath.join needs a fix. 
First, any argument checks have a cost. Second, currently os.path works with 
string-like objects if they implement enough string methods.

But David's proposition looks enough harmless (but this line should be added 
inside the try block). Do you want to add tests David? If apply it to 
posixpath, it should by applied to ntpath too, because currently ntpath.join 
doesn't raise an exceptions for empty list.

> (aside: the isinstance check in _get_sep looks like a bug report waiting to 
> happen...it will do the wrong thing if passed a bytearray or memoryview...)

It is documented that os.path only works with strings and bytes objects. It 
also can work with str-like objects if lucky.

--

___
Python tracker 

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



[issue23780] Surprising behaviour when passing list to os.path.join.

2015-03-26 Thread R. David Murray

R. David Murray added the comment:

Python's philosophy is one of duck typing, which means that in general we just 
let the functions fail with whatever error they produce when the in put 
datatype is wrong.  The error message in this case is fairly straightforward: 
you passed a list and it says that that data type doesn't work.  The linux case 
is a bit more problematic in that it *doesn't* produce an error for invalid 
input.  The problem there is that we can't raise an error if there's only one 
argument for backward compatibility reasons: there almost certainly exists code 
that depends on single argument path returning the argument.  

In theory there shouldn't be code that depends on that single argument being an 
incorrect data type, but it would still only be something we'd consider 
changing in a feature release.

I'm not sure it is worth fixing, frankly, but I've attached a patch we could 
consider applying to 3.5.  (aside: the isinstance check in _get_sep looks like 
a bug report waiting to happen...it will do the wrong thing if passed a 
bytearray or memoryview...)

There may be others who will advocate for a stricter type check or a try/except 
with a "better" error message...I'd be OK with the better error message as long 
as it doesn't break the duck typing rule.

--
keywords: +patch
nosy: +r.david.murray
Added file: http://bugs.python.org/file38701/join_datatype_check.patch

___
Python tracker 

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



[issue23780] Surprising behaviour when passing list to os.path.join.

2015-03-26 Thread Boštjan Mejak

Changes by Boštjan Mejak :


--
versions: +Python 3.5

___
Python tracker 

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



[issue23780] Surprising behaviour when passing list to os.path.join.

2015-03-26 Thread Pikec

Boštjan Mejak (Pikec) added the comment:

Using Python 3.4.3 on Windows 7 Home Premium 64 bit, Service Pack 1:

>>> import os
>>> os.path.join([1, 2, 3])
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Program Files\Python 3.4\lib\ntpath.py", line 108, in join
result_drive, result_path = splitdrive(path)
  File "C:\Program Files\Python 3.4\lib\ntpath.py", line 161, in splitdrive
normp = p.replace(_get_altsep(p), sep)
AttributeError: 'list' object has no attribute 'replace'

I think this atribute error should be handled differently, like informing the 
programmer that you cannot use a list in the join method.

--
nosy: +Boštjan Mejak (Pikec)

___
Python tracker 

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



[issue23780] Surprising behaviour when passing list to os.path.join.

2015-03-26 Thread Florian Bruhin

New submission from Florian Bruhin:

I just accidentally passed a list (instead of unpacking it) to os.path.join. I 
was surprised when it just returned the list unmodified:

>>> os.path.join([1, 2, 3])
[1, 2, 3]

Looking at the source, it simply returns the first argument (path = a; ...; 
return path) when the '*p' part is empty.

I think a "genericpath._check_arg_types('join', a)" or similiar should be added 
at the top, or it should ensure the "*p" part is not empty (as the docstring 
says "two or more pathname components").

--
components: Library (Lib)
messages: 239314
nosy: The Compiler, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Surprising behaviour when passing list to os.path.join.
type: behavior
versions: Python 3.4

___
Python tracker 

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