basedmypy icon indicating copy to clipboard operation
basedmypy copied to clipboard

Make constructors safe

Open KotlinIsland opened this issue 1 year ago • 0 comments

class A:
    def __init__(self): ...
class B:
    def __init__(self, i: int): ...

a: type[A] = B
a()  # no error

This is absurd

What if we removed the constructor from type and put into Init[A] or something?

  • Upstream https://github.com/python/mypy/issues/1831

Additionally:

class A:
    def __init__(self):
        super().__init__(self, 1, 2, 3)  # no error

Introduce a Class type that doesn't allow construction and make type safe and constructable.

KotlinIsland avatar Jan 20 '24 13:01 KotlinIsland