pyrefly
pyrefly copied to clipboard
Disallow instantiating abstract classes
https://pyrefly.org/sandbox/?code=MQAg6gpgNgxg9gWwiALnVALZAFAngJwgDMpcQBlAQwDsATAIzgA8AaTASwGcQuRKQADpQDmEAFCgA7lkIhccAK4gYNEJPzsUENpwyVZNWiCgR91PowUpUuAe2rCe5vCgxxqAOgkSQACQgGBsqKAiYgRKYoCoTccEQc3JyGjEwAXD4AtCAA4hDWhJRQGSjsSDYCyDBYMADW9o4REAyUtZkgAKqcyIQAbqZQAPoothAAFACUqOj2nBUw1vYR+IRGwxWcbRBMFRpI1NaSmhiYyACSACIAouGR0RDcrpQHyJwKAgJw+NajEB7CHnwrHB4AhQnltCBhHBitDaMR7Jp2O42G4+vg2HkYOM2mANFo+HQQPgFM5cK53ME4SBaOxCPNSE45Ip8CB6Pg4JIuvgxGIiOyEOV6jxQZ9rJR6JwUPgWigkOTaDyYFBKJxuABBCVSmUAIRVEHSIENIAAAuLJdL5nK3AqjdTiCAmKMulAiJMMgA+EDmg22o1CVWK5WqkAAYXcMEIWlGGvNOr14x9hrh8UdztdIA9Xqlid9kei5gARAWeUwQABeUPhyNjSYgUAAeQA0mIyBWY1r5rquhM6yAAHJwaxNsRAA
If the class defines an abstract method or inherits an abstract method & doesn't override it, then it cannot be instantiated.
We also need the following:
- disallow calling abstract class methods
- skip return check to allow ... and docstring and NotImplemented for abstract method bodies
To add to this, if a class inherits abstract methods from an ABC and is marked final, it must implement them. Currently Pyrefly does not warn about this while Mypy and Pyright do. Pyright actually doesn't warn about this if the base class is not an ABC, but Mypy still does. Sandbox example.
I don't know if this should be raised as a separate issue/feat or be a part of this one.
Added the two tasks as sub-issues.