Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I agree that mypy can be a bit lacking, but to address a couple of your mypy woes:

- TypedDict is an option but if you can, dataclasses work much better

- mypy does refine Optional[T] to T with an if check. Maybe you need to futz with the compiler options?

- Does Literal["foo"] not work? I've been using it with pydantic for de-serializing a tagged union of dicts and also for function args.

e.g.,

    def call_to_service(api_type: Literal["users", "teams", "orgs") -> None: ...


The problem I had with Literal["foo"] is that at least according to mypy "foo" is a string and it was expecting Literal["foo"].

I think you're right, something must be mixed up. But then again this is the latest version of python and mypy, on intellij, so I'm not sure what I did wrong, it's using otherwise default options.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: