packageurl-python icon indicating copy to clipboard operation
packageurl-python copied to clipboard

Adding type hints

Open gruebel opened this issue 2 years ago • 6 comments

hey 😄

Thanks for the great project 🚀 We are using both your project and CycloneDX to create SBOMs.

I would like to know, if you are interested in adding type hints to your project? I'm a big supporter of improving Python projects by adding type hints to them and reduce the amount of errors, which come from passing the wrong types to a functions or expecting a different result to come back.

I'm willing to do the change, just need to know if you prefer stub files or inline type hints, I usually prefer the latter one? I would also add mypy to your CI to check, if the added type hints make sense or not 🙂

gruebel avatar Oct 08 '22 08:10 gruebel

i support the request. @madpah FYI

this request might be a duplicate to https://github.com/package-url/packageurl-python/issues/65

jkowalleck avatar Oct 09 '22 11:10 jkowalleck

@pombredanne how do you feel about the topic?

i mean, we do have 3 options:

  • adding typing here in the project in code -- generally preferred
  • adding typing here in the project as stubs -- okay-ish
  • adding typing for PURLs in the python/typeshed as stubs -- if yo do not like type hints but the community wants them anyway.

jkowalleck avatar Oct 09 '22 11:10 jkowalleck

@jkowalleck yeah you are right, it is a duplicate. Shame on me 🙈

I'm currently creating the stubs files. So worst case I will create a PR in typeshed and best case I will change them to type annotation directly in the project.

gruebel avatar Oct 09 '22 12:10 gruebel

I thank you so much for your effort, @gruebel

jkowalleck avatar Oct 09 '22 12:10 jkowalleck

@gruebel @jkowalleck Adding typing is fine and likely best done here rather than elsewhere in separate stubs. PR welcomed!

pombredanne avatar Oct 09 '22 13:10 pombredanne

@pombredanne I created an initial PR #101 would be great to get some feedback. Don't be surprised about me changing variable names. I had to do it, because of type changes in the code. If you have any questions, just add some comments, then I will try to explain, why I had to do it like that.

gruebel avatar Oct 09 '22 21:10 gruebel

Implemented in https://github.com/package-url/packageurl-python/pull/101, thanks @gruebel !

tdruez avatar Apr 10 '23 05:04 tdruez