Skip to content

Comments

Allow all subclasses of listed exceptions to be raised without violating contract#143

Open
Glinte wants to merge 1 commit intolife4:masterfrom
Glinte:allow-subclass-raised
Open

Allow all subclasses of listed exceptions to be raised without violating contract#143
Glinte wants to merge 1 commit intolife4:masterfrom
Glinte:allow-subclass-raised

Conversation

@Glinte
Copy link
Contributor

@Glinte Glinte commented Nov 2, 2025

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 of SQLAlchemyError and live on with my life, without listing out all the subclasses of SQLAlchemyError.

Tests were ran, same results on master and this branch (all 3 tests in test_mem_test.py failing)

@orsinium
Copy link
Member

orsinium commented Nov 2, 2025

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.

@Glinte
Copy link
Contributor Author

Glinte commented Nov 3, 2025

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?

@orsinium
Copy link
Member

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.

I have never used flake8 before

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.

@Glinte
Copy link
Contributor Author

Glinte commented Nov 30, 2025

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.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants