Help with syntax warnings

Discussion in 'Python' started by Ivan Shevanski, Sep 30, 2005.

  1. Here's a noob question for everyone (I'm not sure if my first message got
    through, is had a "suspicious header" so sorry for double post is so), is
    there a way to turn off syntax warnings or just make them not visible?


    Thanks,
    -Ivan

    _________________________________________________________________
    Express yourself instantly with MSN Messenger! Download today - it's FREE!
    http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
     
    Ivan Shevanski, Sep 30, 2005
    #1
    1. Advertising

  2. Ivan Shevanski

    Peter Hansen Guest

    Ivan Shevanski wrote:
    > Here's a noob question for everyone (I'm not sure if my first message
    > got through, is had a "suspicious header" so sorry for double post is
    > so), is there a way to turn off syntax warnings or just make them not
    > visible?


    Not sure... what's a "syntax warning"?

    Python has SyntaxError exceptions, which are raised during compilation
    when a program can't even be compiled. They're definitely not warnings,
    and making them invisible would generally be pointless, yet even so all
    you would have to do is catch them and ignore them if that's what you
    wanted to do. But did you mean SyntaxError, or something else?

    -Peter
     
    Peter Hansen, Sep 30, 2005
    #2
    1. Advertising

  3. Ivan Shevanski

    Robert Kern Guest

    Peter Hansen wrote:
    > Ivan Shevanski wrote:
    >
    >>Here's a noob question for everyone (I'm not sure if my first message
    >>got through, is had a "suspicious header" so sorry for double post is
    >>so), is there a way to turn off syntax warnings or just make them not
    >>visible?

    >
    > Not sure... what's a "syntax warning"?
    >
    > Python has SyntaxError exceptions, which are raised during compilation
    > when a program can't even be compiled. They're definitely not warnings,
    > and making them invisible would generally be pointless, yet even so all
    > you would have to do is catch them and ignore them if that's what you
    > wanted to do. But did you mean SyntaxError, or something else?


    In [1]: SyntaxWarning?
    Type: classobj
    String Form: exceptions.SyntaxWarning
    Namespace: Python builtin
    Docstring:
    Base class for warnings about dubious syntax.

    --
    Robert Kern


    "In the fields of hell where the grass grows high
    Are the graves of dreams allowed to die."
    -- Richard Harter
     
    Robert Kern, Sep 30, 2005
    #3
  4. Ivan Shevanski wrote:
    > is there a way to turn off syntax warnings or just make them not
    > visible?


    import warnings
    warnings.filterwarnings('ignore', category=SyntaxWarning)
     
    Leif K-Brooks, Sep 30, 2005
    #4
  5. Ivan Shevanski

    Peter Hansen Guest

    Robert Kern wrote:
    > Peter Hansen wrote:
    >>Not sure... what's a "syntax warning"?

    >
    > In [1]: SyntaxWarning?
    > Type: classobj
    > String Form: exceptions.SyntaxWarning
    > Namespace: Python builtin
    > Docstring:
    > Base class for warnings about dubious syntax.


    Wow... Python detects "dubious syntax"? And here I thought programming
    was rather black and white, it's right or it's wrong.

    (He notes examples such as assigning to None and "unqualified exec is
    not allowed in function" etc.)

    I guess I've never accidentally hit one of those. Seems like, if I had,
    I'd probably want to fix the problem rather than hide it, as with most
    warnings from C compilers.

    -Peter
     
    Peter Hansen, Sep 30, 2005
    #5
  6. Ivan Shevanski schreef:
    > Here's a noob question for everyone (I'm not sure if my first message
    > got through, is had a "suspicious header" so sorry for double post is
    > so), is there a way to turn off syntax warnings or just make them not
    > visible?


    Those warnings are something I have never seen and even have never heard
    about, even though I now found out there's a section in the library
    reference about them. It seems you can define filters to specify what
    you want to do with the warnings; you can read all about it at
    http://docs.python.org/lib/module-warnings.html

    --
    If I have been able to see further, it was only because I stood
    on the shoulders of giants. -- Isaac Newton

    Roel Schroeven
     
    Roel Schroeven, Sep 30, 2005
    #6
  7. Peter Hansen wrote:

    > Wow... Python detects "dubious syntax"? And here I thought programming
    > was rather black and white, it's right or it's wrong.


    SyntaxWarnings are issued for things that has never been valid nor well-
    defined nor especially clever, but has been handled (in some more or less
    reasonable way) by the CPython compiler. In practice, syntax warnings
    will turn into errors in future releases.

    > (He notes examples such as assigning to None and "unqualified exec is
    > not allowed in function" etc.)


    Compare and contrast:

    Python 2.3.4 (#53, May 25 2004, 21:17:02)
    >>> None = "hello"

    <stdin>:1: SyntaxWarning: assignment to None

    Python 2.4.1 (#65, Mar 30 2005, 09:13:57)
    >>> None = "hello"

    SyntaxError: assignment to None

    </F>
     
    Fredrik Lundh, Sep 30, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JnCodesigns

    Help with syntesis warnings

    JnCodesigns, Jun 13, 2005, in forum: VHDL
    Replies:
    2
    Views:
    3,716
    scs9gp
    Apr 30, 2007
  2. Ivan Shevanski

    Turning off syntax warnings?

    Ivan Shevanski, Sep 30, 2005, in forum: Python
    Replies:
    0
    Views:
    239
    Ivan Shevanski
    Sep 30, 2005
  3. gaulle
    Replies:
    3
    Views:
    382
    gaulle
    Aug 10, 2004
  4. Guest

    Re: Help - buried in compiler warnings.

    Guest, Feb 22, 2006, in forum: C Programming
    Replies:
    103
    Views:
    1,591
    Flash Gordon
    Feb 25, 2006
  5. Ted Sung
    Replies:
    1
    Views:
    330
    Sherm Pendley
    Aug 30, 2004
Loading...

Share This Page