seperman / deepdiff

DeepDiff: Deep Difference and search of any Python object/data. DeepHash: Hash of any object based on its contents. Delta: Use deltas to reconstruct objects by adding deltas together.
http://zepworks.com
Other
2.04k stars 226 forks source link

Type hints/stubs #352

Open ethiy opened 2 years ago

ethiy commented 2 years ago

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.

seperman commented 2 years ago

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.

ethiy commented 2 years ago

I think this article synthesizes very well the issue.

seperman commented 1 year ago

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.

dpinol commented 1 year ago

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

sveinse commented 8 months ago

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.

rafrafek commented 7 months ago

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.

seperman commented 7 months ago

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

rafrafek commented 7 months ago

@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 😅