8000 Exceptions can't take more than one argument · Issue #142 · PythonJS/PythonJS · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Exceptions can't take more than one argument #142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ChrisBarker-NOAA opened this issue Sep 29, 2014 · 1 comment
Open

Exceptions can't take more than one argument #142

ChrisBarker-NOAA opened this issue Sep 29, 2014 · 1 comment

Comments

@ChrisBarker-NOAA
Copy link

I've defined a custom Exception that takes more than one argument to __init__:

class InvalidUnitError(UnitConversionError):
    """
    Exception raised when a unit is not in the Unit conversion database

    """
    def __init__(self, unit, type = ""):
        self.unit = unit
        self.type = type

as you can see, it takes two arguments -- Gython chokes on this:

  File "/Users/chris.barker/Temp/Py2JS_test/Gython/pythonjs/python_to_pythonjs.py", line 1404, in visit_Raise
    raise SyntaxError( self.format_error('raise Error(x) can only have a single argument') )
SyntaxError: line 129
            FromUnit = self.Synonyms[FromUnit]
        except KeyError:
            raise InvalidUnitError(FromUnit, self.Name)
raise Error(x) can only have a single argument

One can certainly argue that changing the API to an Exception is bad form that pythonjs doesn't support, but I thought I'd log this.

@ChrisBarker-NOAA
Copy link
Author

Actuallly -- looking more, it turns out that Exceptions are designed to take an arbitraty number of arguments, which by default get stored in the "args" attribute:

In [10]: e = Exception("this", "is", "more", "than", "one", "argument")

In [11]: e.args
Out[11]: ('this', 'is', 'more', 'than', 'one', 'argument')

In [12]: print e
('this', 'is', 'more', 'than', 'one', 'argument')

So you may want to support this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants
@ChrisBarker-NOAA and others
0