Nesting Custom Errors in Classes
Cameron Simpson
cs at cskk.id.au
Tue Jul 23 21:30:34 EDT 2019
On 24Jul2019 11:47, DL Neil <PythonList at DancesWithMice.info> wrote:
>On 24/07/19 10:07 AM, Cameron Simpson wrote:
>>On 24Jul2019 07:21, DL Neil <PythonList at DancesWithMice.info> wrote:
>...
>>Get some linting tools. They're great for catching this kind of error.
>
>SublimeText has SublimeLinter and PycodeStyle installed, but I'm still
>familiarising myself with ST. Nothing is reported.
>
>Any advice/correction/improvement would be most welcome...
Hmm. I'd expect a linter to catch this:
# forgot FooException
from foo import FooClass
def f():
raise FooException
Can you test that with a small script at your end (with real imports and
names of course)?
I lint from the command line with this script:
https://bitbucket.org/cameron_simpson/css/src/tip/bin-cs/lint
which runs a few Python linters for Python.
WRT SublimeText, PycodeStyle likely only checks style (I've now shifted
to an automatic formatter for this) and SublimeLinter's PythonLinter
page is... silent; it looks like a base class for other actual linters.
You might need to do some more digging. Maybe you need some addition
lint stuff for SublimeText.
>>The tricky bit with dynamic language like Python is that some naming
>>errors (missed imports) aren't apparent until the code passes through
>>that path. Linters can cover a lot of this with static analysis.
>
>Exactly!
>(PyTest and coverage tools were no help - they import correctly (and
>test adequately), but I didn't open those (separate) modules to notice
>the multiple import-s)
>
>Hope springs eternal ... there must be a better way???
A good linter is usually decent at complaining about code using names
that aren't defined (not imports, not otherwise defined such as a
function or a variable assignment).
>(well yes, not wishing to 'flog a dead horse' (nor any horse for that
>matter) I'm pleased at the (lack of negative) response to my allied
>question about nested classes, which would solve the original problem)
There's nothing "wrong" with it. It is uncommon. But like a lot of
things, the value (or cost/pitfalls) come with how things are to be
used.
Cheers,
Cameron Simpson <cs at cskk.id.au>
More information about the Python-list
mailing list