-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Background
Some classes define __new__ so that calling the class always instantiates some specific subclass; for example, instantiating pathlib.Path always produces a PosixPath or a WindowsPath.
Here is an example.
Note that you can type __new__ as def __new__(cls) -> Foo | Bar, and pyright correctly understands that if you write b = Base(), b's type is Foo | Bar.
Describe the bug
However, if your base class is abstract, pyright reports a "Cannot instantiate abstract class" error, even if the class(es) it actually instantiates are concrete. Example
Expected result
I think the reportAbstractUsage check should base its decision on __new__'s return type. If it returns a concrete class, or union of concrete classes, it should not flag it as an attempt to instantiate an abstract class.