ponyorm / pony

Pony Object Relational Mapper
Apache License 2.0
3.61k stars 243 forks source link

Create typings via .pyi files #537

Open Ryuno-Ki opened 4 years ago

Ryuno-Ki commented 4 years ago

While filling https://github.com/python/typeshed/issues/4361 I received feedback by Alexander @kozlovsky to fill an issue against Pony as well.

Note, that @fluffy-critter created some typing information in https://github.com/ponyorm/pony/issues/479

Alexander told me, that Pony supports Python 2 and 3. However, the typeshed repo lists other packages supporting both versions, too.

Please consider adding typing information as .pyi files (or get in touch with the people at typeshed to learn more about how to add some).

Ryuno-Ki commented 4 years ago

I started working on this and will need another evening to complete the first round (there are lots of Anys + some type: ignore lines to resolve afterwards).

It's a lot of code, so I want to summarise some resources here.

For Python2 code bases, it's possible to add some information as comments: https://mypy.readthedocs.io/en/stable/python2.html

However, I used mypy's stubgen to generate the first batch of .pyi files: https://mypy.readthedocs.io/en/stable/stubs.html

I dropped the thirdparty directory as well as tests and examples.

There's a list of built-in types: https://mypy.readthedocs.io/en/stable/builtin_types.html and some more complex types. But for me, the inheritance makes some things harder. I need to take a fresh look at it before I can fill issues (after this PR got merged).

Those errors could indicate some bogus logic in the library, so it's worth to take a look at it.

Since I couldn't find a directory indicating a CI system, I'd need some help in checking the changes across different Python versions and platforms so to not break existing code.

glacion commented 3 years ago

@Ryuno-Ki do you have any updates on this? I'd like to work on this as well if necessary.

Ryuno-Ki commented 3 years ago

Hm, I moved houses this month and I think it was on one of the old machines I'm still looking my charger for …

Go ahead, @glacion. I outlined my process above. I seem to not have pushed my code (at least I couldn't find a fork on GitHub :eyes:),

glacion commented 3 years ago

That's rough 😔 yeah i am working on something else nowadays, but i'll look into it if i get the chance

Ryuno-Ki commented 3 years ago

Hm, what about collaborating then? If you fork the repo and open a PR (marked as draft), perhaps I could push commits to it and we both part the work?

glacion commented 3 years ago

yeah i am open to collab work, it should be you that opens the draft PR though, i would rather add upon the work you've already done, since even though you've lost the work you've done, you probably have more grasp on what to actually do than i am.

Ryuno-Ki commented 3 years ago

@glacion I was about to restore my state today … and discovered, that I had a local branch which I did not push -.-

Here it is: https://github.com/ponyorm/pony/compare/orm...Ryuno-Ki:537-type-stubs?expand=1

glacion commented 3 years ago

That's great and sad at the same time 😆 So to my understanding, now we have to go through the pyi files and fix the ones that aren't accurate or missing. Am i correct here?

Ryuno-Ki commented 3 years ago

Correct. I had a diff of ~12 commits before rebasing against ORM. So we would need to check the recent commits as well (as the PR would add some files, which might got refactored in the mean time).

glacion commented 3 years ago

Hey man, sorry. I just started a new job and it's going to take some time before i get oriented and available to work on this. Wanted to let you know

Ryuno-Ki commented 3 years ago

No hurries. It stalled for several months. A few more days won't hurt, I guess.

Congratulations to your new job!

Jonesus commented 2 years ago

In case someone is still looking for static typing for Pony, I started working on it in a separate package for now, with the goal of eventually getting to merge it here: https://github.com/Jonesus/pony-stubs

Ryuno-Ki commented 2 years ago

FYI: I moved to SQLalchemy and no longer use Pony.