Allow all subclasses of listed exceptions to be raised without violating contract#143
Allow all subclasses of listed exceptions to be raised without violating contract#143Glinte wants to merge 1 commit intolife4:masterfrom
Conversation
|
the linter cannot resolve subclasses. it would be nice to migrate the linter from flake8 to mypy (like refurb does) to be able to properly resolve types but that's a giant project for which I'll never have time. so i try to keep the runtime behavior close to the current static analysis capabilities. |
|
I didn't think about deal's linter, that makes sense but sucks. I have never used flake8 before, let alone writing a plugin. Are you saying that it is impossible to use flake8 to understand type information properly, so all that is possible is an exact match without switching to mypy? |
|
the current linter uses astroid to do some basic type resolution, which has limited type inference. it's possible to extend the linter to resolve with astroid base classes of the exception class.
You should, linters are good :) Well, ruff is the new mainstream, it's generally a better version of flake8. Although you can't write third-party plugins for ruff, so we can't migrate deal to ruff. But, again, if I had time for a full rewrite of the linter, I'd use mypy instead. |
|
I am quite new to serious (python) coding, so when I learned about linting 1-2 years ago, the recommended linter is already ruff. I'm quite glad that I don't have to interact with flake8 tbh, since the linting time seems to be off the roof. |
This is a pretty breaking change, but I made the PR just to start the discussion.
Imo it makes very little sense to not allow subclasses. I am using many third-party libraries, and basically all of them provide an exception hierarchy, for example SQLAlchemy has around 10 exception subclasses of
SQLAlchemyError. Of course, it would be best if I rewrap the exceptions again, but I really want to just tell deal and the consumers of my function that it may raise any subclass ofSQLAlchemyErrorand live on with my life, without listing out all the subclasses ofSQLAlchemyError.Tests were ran, same results on master and this branch (all 3 tests in test_mem_test.py failing)