deepdiff icon indicating copy to clipboard operation
deepdiff copied to clipboard

Type hints/stubs

Open ethiy opened this issue 3 years ago • 8 comments

It would be really helpful to have type hints or stubs for this package to help the developer in his experience using the library*.

I have found no alternative solution, for now.

ethiy avatar Sep 27 '22 18:09 ethiy

Can you please give me an example of how type hints help the developers in using the library? I understand if they were contributing code but not very clear to me how it could improve the user experience. Thanks,

Sep Dehpour

On Sep 27, 2022, at 11:19 AM, Oussama ENNAFII @.***> wrote:

 It would be really helpful to have type hints or stubs for this package to help the developer in his experience using the library*.

I have found no alternative solution, for now.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.

seperman avatar Sep 27 '22 19:09 seperman

I think this article synthesizes very well the issue.

ethiy avatar Oct 10 '22 12:10 ethiy

Ok that article needs a subscription to "real Python". Since the type hints don't cause any performance improvement in cPython, we don't have it as a priority task. We can add the type hints to the new functions though.

seperman avatar Dec 12 '22 06:12 seperman

Type hints are extremely useful for discovering functions, arguments... and also for detecting regressions https://www.infoworld.com/article/3630372/get-started-with-python-type-hints.html

dpinol avatar Oct 11 '23 08:10 dpinol

Type annotations are a very useful tool to improve code quality. It helps in describing the expected behavior and help the developers write more accurate code. Especially when paired with an IDE that analyse type annotations while coding. Many python projects requires type annotations these days. All type annotation-enabled projects using deepdiff wil actually get a warning from mypy that deepdiff is missing library stubs. It would be very nice if this could be considered. Thanks.

edit As I'm looking at deepdiff internals to create a typing stub for my own use of deepdiff, I see that the job of type annotating deepdiff is going to be a considerable undertaking. The types of the various objects used are rather amorphous, which makes typing harder.

sveinse avatar Mar 27 '24 11:03 sveinse

how it could improve the user experience


This is what I see when using DeepDiff:

image

This is what I see when using Flask:

image

The difference is that I don't know what an Unknown is, but I know what a str is. Or should I use list[str] etc.

For me knowing the type helps. I don't need to look up the documentation so often to know what can I put as a parameter and what I can't.

rafrafek avatar Apr 04 '24 15:04 rafrafek

@rafrafek Is this a screenshot from your IDE? What IDE is that?

seperman avatar Apr 04 '24 17:04 seperman

@seperman Yes, it's from my IDE. It's VS Code with Python and Pylance extensions.

I'm using Pylance static type checker in "strict" mode. Strict mode may be too strict for existing projects, but I can recommend it for new ones. Pylance uses Pyright under the hood. Pyright can be used as a CLI tool or with pre-commit.

I'm using standard light theme with "sync with OS" option, so it switches to standard dark theme together with macOS after the sunset. I think most people use dark theme all the time so my IDE may look exotic even for VS Code users 😅

rafrafek avatar Apr 04 '24 18:04 rafrafek