RE: PEP8 compliance and exception messages ?

2010-12-08 Thread Gerald Britton
I'm a bit late to the discussion, but remembering that raise takes an
expression, I can break it up like this:

 raise (
... Exception (
... Long 
... exception 
... text.
... )
... )
Traceback (most recent call last):
  File stdin, line 3, in module
Exception: Long exception text

Then, you can indent the individual lines any way you like.
-- 
Gerald Britton
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP8 compliance and exception messages ?

2010-12-07 Thread shearichard
On Dec 6, 6:21 pm, Ben Finney ben+pyt...@benfinney.id.au wrote:
 shearichard shearich...@gmail.com writes:
  Hi - PEP8 says lines should not exceed 79 characters in length
  (http://www.python.org/dev/peps/pep-0008/).

  So if you've got some code that looks like this :

  raise fooMod.fooException(Some message which is quite long)

 PEP 8 also says those names are poorly chosen. Better:

     raise foomod.FooException(Some message which is quite long)

  raise fooMod.fooException(\
          Some message \
          which is quite long)

 Take advantage of the parsing of string literals and parenthesis:

     raise foomod.FooException(
         Some message
          which is quite long)

 and for the sake of my eyes, avoid camelCase.

OK you got me ! Thanks for pointing this out, I will take a look at
the relevant section
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP8 compliance and exception messages ?

2010-12-07 Thread shearichard
On Dec 7, 9:17 am, Andreas Waldenburger use...@geekmail.invalid
wrote:
 On Mon, 6 Dec 2010 00:22:49 -0500 Andreas Waldenburger 
 use...@geekmail.invalid wrote:



  On Sun, 5 Dec 2010 19:52:54 -0800 Chris Rebert c...@rebertia.com
  wrote:

   On Sun, Dec 5, 2010 at 7:40 PM, shearichard shearich...@gmail.com
   wrote:
Hi - PEP8 says lines should not exceed 79 characters in length
(http://www.python.org/dev/peps/pep-0008/).

So if you've got some code that looks like this :

raise fooMod.fooException(Some message which is quite long)

... and assuming a certain amount of indenting you're going to
break that guideline.

[etc.]

   [...]
   Alternatively, you could disregard PEP 8 on this point on the
   grounds that the 79/80 characters per line limit is outdated.

  Maybe, but it's not outmoded.

 As a more useful (I hope) reply, my opinion in this case is to just make the 
 line a little longer. Even if you can't read it all at once, it is pretty 
 obvious what comes next: The rest of the error message. There is no 
 additional functionality hidden there, and you don't need to see it all at 
 once to grasp the meaning of the code.

 /W

 --
 To reach me via email, replace INVALID with the country code of my home
 country.  But if you spam me, I'll be one sour Kraut.

Thanks to everyone for their helpful replies.

Thanks for the pointers towards implicit (or explicit) string
concatenation - just what was needed.

I appreciate everyone has different opinions by I'm happy to try to
stick with 79 character lines for the meantime - largely for the 'may
have a wide screen but like to have lots of files open in slim
windows' reason.

regards

Richard.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP8 compliance and exception messages ?

2010-12-06 Thread Andreas Waldenburger
On Mon, 6 Dec 2010 00:22:49 -0500 Andreas Waldenburger 
use...@geekmail.invalid wrote:

 On Sun, 5 Dec 2010 19:52:54 -0800 Chris Rebert c...@rebertia.com
 wrote:
 
  On Sun, Dec 5, 2010 at 7:40 PM, shearichard shearich...@gmail.com
  wrote:
   Hi - PEP8 says lines should not exceed 79 characters in length
   ( http://www.python.org/dev/peps/pep-0008/ ).
  
   So if you've got some code that looks like this :
  
   raise fooMod.fooException(Some message which is quite long)
  
   ... and assuming a certain amount of indenting you're going to
   break that guideline.
  
   [etc.]
  
  [...]
  Alternatively, you could disregard PEP 8 on this point on the
  grounds that the 79/80 characters per line limit is outdated.
  
 Maybe, but it's not outmoded.
 
As a more useful (I hope) reply, my opinion in this case is to just make the 
line a little longer. Even if you can't read it all at once, it is pretty 
obvious what comes next: The rest of the error message. There is no additional 
functionality hidden there, and you don't need to see it all at once to grasp 
the meaning of the code.

/W


-- 
To reach me via email, replace INVALID with the country code of my home 
country.  But if you spam me, I'll be one sour Kraut.

-- 
http://mail.python.org/mailman/listinfo/python-list


PEP8 compliance and exception messages ?

2010-12-05 Thread shearichard
Hi - PEP8 says lines should not exceed 79 characters in length
( http://www.python.org/dev/peps/pep-0008/ ).

So if you've got some code that looks like this :

raise fooMod.fooException(Some message which is quite long)

... and assuming a certain amount of indenting you're going to break
that guideline.

However there's a way around that ! You can do this ...

raise fooMod.fooException(\
Some message \
which is quite long)

... but the trouble is when that Exception is raised the message is
displayed as :

Some message which is quite long


I'm aware that a foolish consistency is the hobgoblin of something or
the other so maybe I should just let the PEP8 verifier complain but
otherwise does anyone have any ideas for how to get around this ?


Thanks

richard

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP8 compliance and exception messages ?

2010-12-05 Thread Chris Rebert
On Sun, Dec 5, 2010 at 7:40 PM, shearichard shearich...@gmail.com wrote:
 Hi - PEP8 says lines should not exceed 79 characters in length
 ( http://www.python.org/dev/peps/pep-0008/ ).

 So if you've got some code that looks like this :

 raise fooMod.fooException(Some message which is quite long)

 ... and assuming a certain amount of indenting you're going to break
 that guideline.

 However there's a way around that ! You can do this ...

 raise fooMod.fooException(\
        Some message \
        which is quite long)

 ... but the trouble is when that Exception is raised the message is
 displayed as :

 Some message                     which is quite long


 I'm aware that a foolish consistency is the hobgoblin of something or
 the other so maybe I should just let the PEP8 verifier complain but
 otherwise does anyone have any ideas for how to get around this ?

Use implicit string literal concatenation:

raise fooMod.fooException(
Some message 
which is quite long)
#) # you could also put the closing paren here instead

Alternatively, you could disregard PEP 8 on this point on the grounds
that the 79/80 characters per line limit is outdated.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP8 compliance and exception messages ?

2010-12-05 Thread MRAB

On 06/12/2010 03:40, shearichard wrote:

Hi - PEP8 says lines should not exceed 79 characters in length
( http://www.python.org/dev/peps/pep-0008/ ).

So if you've got some code that looks like this :

raise fooMod.fooException(Some message which is quite long)

... and assuming a certain amount of indenting you're going to break
that guideline.

However there's a way around that ! You can do this ...

raise fooMod.fooException(\
 Some message \
 which is quite long)

... but the trouble is when that Exception is raised the message is
displayed as :

Some message which is quite long


I'm aware that a foolish consistency is the hobgoblin of something or
the other so maybe I should just let the PEP8 verifier complain but
otherwise does anyone have any ideas for how to get around this ?


You can use implied string concatenation:

 abc def
'abcdef'

so:

raise fooMod.fooException(
  Some message 
  which is quite long)
--
http://mail.python.org/mailman/listinfo/python-list


Re: PEP8 compliance and exception messages ?

2010-12-05 Thread Ben Finney
shearichard shearich...@gmail.com writes:

 Hi - PEP8 says lines should not exceed 79 characters in length
 ( http://www.python.org/dev/peps/pep-0008/ ).

 So if you've got some code that looks like this :

 raise fooMod.fooException(Some message which is quite long)

PEP 8 also says those names are poorly chosen. Better:

raise foomod.FooException(Some message which is quite long)

 raise fooMod.fooException(\
 Some message \
 which is quite long)

Take advantage of the parsing of string literals and parenthesis:

raise foomod.FooException(
Some message
 which is quite long)

and for the sake of my eyes, avoid camelCase.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP8 compliance and exception messages ?

2010-12-05 Thread Andreas Waldenburger
On Sun, 5 Dec 2010 19:52:54 -0800 Chris Rebert c...@rebertia.com wrote:

 On Sun, Dec 5, 2010 at 7:40 PM, shearichard shearich...@gmail.com
 wrote:
  Hi - PEP8 says lines should not exceed 79 characters in length
  ( http://www.python.org/dev/peps/pep-0008/ ).
 
  So if you've got some code that looks like this :
 
  raise fooMod.fooException(Some message which is quite long)
 
  ... and assuming a certain amount of indenting you're going to break
  that guideline.
 
  [etc.]
 
 Use implicit string literal concatenation:
 
 [...]
 
But isn't explicit string literal concatenation better than implicit string 
literal concatenation?

... sorry ...

On a more serious note:

 Alternatively, you could disregard PEP 8 on this point on the grounds
 that the 79/80 characters per line limit is outdated.
 
Maybe, but it's not outmoded.

/W

-- 
To reach me via email, replace INVALID with the country code of my home 
country.  But if you spam me, I'll be one sour Kraut.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP8 compliance and exception messages ?

2010-12-05 Thread Tim Harig
On 2010-12-06, Andreas Waldenburger use...@geekmail.invalid wrote:
 On Sun, 5 Dec 2010 19:52:54 -0800 Chris Rebert c...@rebertia.com wrote:

 On Sun, Dec 5, 2010 at 7:40 PM, shearichard shearich...@gmail.com
 wrote:
  Hi - PEP8 says lines should not exceed 79 characters in length
  ( http://www.python.org/dev/peps/pep-0008/ ).
 
  So if you've got some code that looks like this :
 
  raise fooMod.fooException(Some message which is quite long)
 
  ... and assuming a certain amount of indenting you're going to break
  that guideline.
 
  [etc.]
 
 Use implicit string literal concatenation:
 
 [...]
 
 But isn't explicit string literal concatenation better than implicit
 string literal concatenation?

So add the +, it really doesn't change it much.

 Alternatively, you could disregard PEP 8 on this point on the grounds
 that the 79/80 characters per line limit is outdated.
 
 Maybe, but it's not outmoded.

I would say that it is not even outdated.  Just because you happen to enjoy
longer lines doesn't mean that everybody does.  Not all progammers have
20/10 vision and even those who have hardware to handled it don't
necessarily like having a single piece of code take up their entire display
just to be readable.  Many of us like the extra ability that wider screen
technology gives us to actually be able to view more of the file at once
by splitting the display into a couple of columns.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP8 compliance and exception messages ?

2010-12-05 Thread Steven D'Aprano
On Mon, 06 Dec 2010 06:15:06 +, Tim Harig wrote:

 But isn't explicit string literal concatenation better than implicit
 string literal concatenation?
 
 So add the +, it really doesn't change it much.

Perhaps not *much*, but it *may* change it a bit.

Implicit concatenation of literals is promised to be handled by the 
compiler, at compile time:

 from dis import dis
 dis(compile(s = 'hello' 'world', , single))
  1   0 LOAD_CONST   0 ('helloworld')
  3 STORE_NAME   0 (s)
  6 LOAD_CONST   1 (None)
  9 RETURN_VALUE

This holds all the way back to Python 1.5 and probably older.

But explicit concatenation may occur at run-time, depending on the 
implementation and the presence or absence of a keyhole optimizer. E.g. 
in Python 2.4:

 dis(compile(s = 'hello' + 'world', , single))
  1   0 LOAD_CONST   0 ('hello')
  3 LOAD_CONST   1 ('world')
  6 BINARY_ADD
  7 STORE_NAME   0 (s)
 10 LOAD_CONST   2 (None)
 13 RETURN_VALUE



A small difference, but a real one.


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list