473,782 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Path PEP: What should Path(None) do?

Currently it returns Path('None'). This means I have to do a check on
input before pathifying it to make sure it is not None.

Perhaps it should throw ValueError?
--
Michael Hoffman
Jul 25 '05 #1
3 1329
Michael Hoffman wrote:
Currently it returns Path('None'). This means I have to do a check on
input before pathifying it to make sure it is not None.

Perhaps it should throw ValueError?


The problem is that Path() currently acts like str() and will therefore
accept almost anything that has a string representation.

We can do two things: 1) restrict Path.__new__ arguments to be strings
or unicode only, or 2) special-case None and what else comes in mind.

I think 1) is the proper solution. Path() is not a general stringifier
as str(), and shouldn't act like one.

Reinhold
Jul 25 '05 #2
Michael Hoffman wrote:
Currently it returns Path('None'). This means I have to do a check on
input before pathifying it to make sure it is not None.

Perhaps it should throw ValueError?


Without checking, I suspect it is merely doing str(x) or unicode(x) on
whatever is passed to it:
path(None) path(u'None') path(object()) path(u'<object object at 0x00AAB438>') path(3.14159)

path(u'3.14159' )

Therefore I think the question should be broadened beyond just None.
Should Path(x) simply call str(x) on the object or should it raise
ValueError or TypeError or something if it's not a basestring?

Given that pretty much *everything* in Python can have str() called on
it, I think we should ask for a modicum of type-safety here and reject
non-strings as input.

-Peter
Jul 25 '05 #3
Peter Hansen wrote:
Michael Hoffman wrote:
Currently it returns Path('None'). This means I have to do a check on
input before pathifying it to make sure it is not None.

Perhaps it should throw ValueError?


Without checking, I suspect it is merely doing str(x) or unicode(x) on
whatever is passed to it:
>>> path(None) path(u'None') >>> path(object()) path(u'<object object at 0x00AAB438>') >>> path(3.14159)

path(u'3.14159' )

Therefore I think the question should be broadened beyond just None.
Should Path(x) simply call str(x) on the object or should it raise
ValueError or TypeError or something if it's not a basestring?

Given that pretty much *everything* in Python can have str() called on
it, I think we should ask for a modicum of type-safety here and reject
non-strings as input.


Settled.

Reinhold
Jul 25 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
11549
by: Richard Wesley | last post by:
I am trying to set the mod date on a file (Linux) as part of a unit test run. I can just wait one second, but that slows the test down. A better solution would be to tweak the mod date on a file, but os.path does not seem to have setmtime. Is there any simple way to do this? TIA, --
1
2601
by: Peter Åstrand | last post by:
There's a new PEP available: PEP 324: popen5 - New POSIX process module A copy is included below. Comments are appreciated. ---- PEP: 324 Title: popen5 - New POSIX process module
31
3928
by: John Roth | last post by:
I'm adding a thread for comments on Gerrit Holl's pre-pep, which can be found here: http://tinyurl.com/2578q Frankly, I like the idea. It's about time that all of the file and directory stuff in the os module got objectified properly (or at least with some semblance of OO propriety!) In the issues section:
28
2356
by: The Eternal Squire | last post by:
PEP: 336 Title: Make None Callable Version: $Revision: 1.1 $ Last-Modified: $Date: 2004/11/03 16:58:30 $ Author: Andrew McClelland Status: Draft Type: Standards Track Content-Type: text/plain Created: 28-Oct-2004 Post-History:
18
3051
by: Steven Bethard | last post by:
In the "empty classes as c structs?" thread, we've been talking in some detail about my proposed "generic objects" PEP. Based on a number of suggestions, I'm thinking more and more that instead of a single collections type, I should be proposing a new "namespaces" module instead. Some of my reasons: (1) Namespace is feeling less and less like a collection to me. Even though it's still intended as a data-only structure, the use cases...
70
4116
by: Michael Hoffman | last post by:
Many of you are familiar with Jason Orendorff's path module <http://www.jorendorff.com/articles/python/path/>, which is frequently recommended here on c.l.p. I submitted an RFE to add it to the Python standard library, and Reinhold Birkenfeld started a discussion on it in python-dev <http://mail.python.org/pipermail/python-dev/2005-June/054438.html>. The upshot of the discussion was that many python-dev'ers wanted path added to the...
19
2975
by: Nicolas Fleury | last post by:
Hi everyone, I would to know what do you think of this PEP. Any comment welcomed (even about English mistakes). PEP: XXX Title: Specialization Syntax Version: $Revision: 1.10 $ Last-Modified: $Date: 2003/09/22 04:51:49 $ Author: Nicolas Fleury <nidoizo at gmail.com> Status: Draft Type: Standards Track
108
6461
by: Bryan Olson | last post by:
The Python slice type has one method 'indices', and reportedly: This method takes a single integer argument /length/ and computes information about the extended slice that the slice object would describe if applied to a sequence of length items. It returns a tuple of three integers; respectively these are the /start/ and /stop/ indices and the /step/ or stride length of the slice. Missing or out-of-bounds indices are handled in a manner...
7
2701
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about the goals -- the make statement is mostly syntactic sugar for:: class <name> <tuple>: __metaclass__ = <callable>
0
9641
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10080
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6735
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2875
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.