• TehPers
    link
    fedilink
    English
    210 months ago

    mypy is great, but it doesn’t come close to what you can do with TypeScript. I don’t think that’s necessarily a jab at Python (though TypeVar’s limitations do come up here and there), more just throwing TypeScript on a pedestal.

      • TehPers
        link
        fedilink
        English
        110 months ago

        I really wish Python had multi-line lambdas. Sadly Python is very opinionated in ways I don’t quite understand, but I can at least respect while using it.

        For interfaces, honestly all I can suggest is using an ABC with only @abstractmethods. It’s not perfect, but it’s basically what you’d do in C++ anyway. If you’re looking for an interface that models data, you could look at dataclasses or TypedDict (depending on what kind of data it is), but it’s just not going to match what’s possible in TS sadly (mapped types, conditional types, complex union types, custom type guards, etc).