dataclass-wizard icon indicating copy to clipboard operation
dataclass-wizard copied to clipboard

Fix mypy type errors

Open AdiNar opened this issue 3 years ago • 2 comments

#51 I've look around the type errors that mypy found. Unfortunately it's harder than I thought - some of them are caused by the fact that some code is valid in dynamic context, but making it understandable by mypy is not trivial. Another group will require some changes in code. Yet another group of errors might probably be fixed by using TypeGuards, but this is a new feature from python3.10.

In this PR I fix almost all errors in parsers.py file. There is one left and fixing it will probably require more changes in code (Liskov principle is broken there, I described it more in the commit message).

More errors arise after the change, but as far as my changes make sense, they are caused by mypy having more data to analyze.

I attach mypy output before and after the changes and the diff between them. Checked on project virtualenv with python3.8, all test are passing. mypy_diff.txt mypy_new.txt mypy_old.txt

AdiNar avatar Jul 19 '22 16:07 AdiNar

Hi @AdiNar, thanks again for opening this PR. First off, just wanted to say that I appreciate you taking the time and effort to put all this together. I understand that navigating the intricacies of this project's codebase can sometimes be a challenge and an uphill struggle, and other times just an exercise in futility because it seems like there is wall after wall to punch through before you finally break into the treasure room, where all the good stuff is at.

That said, I do have plans in the long-term to look into refactoring the codebase, to break it out and at the least to make it a little more digestible and easier to understand, and considerably easier to locate things so it feels less like spaghetti code and a bit more like everything's neater and more well rounded, so we're not looking at a half dozen files or modules to try to hunt down the cause of an obscure bug for example (yep, definitely been there). However that's still in the pipeline for now, and I'll likely add a milestone to help track that effort since I personally feel like it'll be worthwhile to knock down a pin or two to push that through the goalpost when time allows.

I do apologize for not looking at the PR till now, but I've been kept busy with life and other stuff and haven't been able to take an active interest in personal projects lately, though hopefully that will change starting soon. Last month (July) was in fact a pretty eventful month for me; I had a third row seat at a solid fireworks show, turned 30 for the first time ever - not a milestone to take lightly of course, found out I was left-handed at a sport I had never played before, attended my very first live orchestra event and coincidentally also sat through one of the original Star Wars movies that I'd only heard of in passing and in plenty of memes, and also came head-to-head with COVID for the first time ever. So all in all it was rather eventful, and though not all of it was good, I enjoyed my time and was caught up by events and the going ons for the most part.

All that out of the way, I do want to mention that I have some upcoming important changes and updates I am planning to push out rather soon, so depending on timing and other factors I might ask you to merge or pull in the changes once I have everything wrapped up and added to the main branch. Again, if it is too much work I can also set some time apart to address the mypy and type errors with the updated codebase, since I feel I have a better understanding of how it all comes together now.

Also, fingers crossed but I definitely forsee that hopefully by the end of the month these changes can be integrated in the project codebase, and we should be able to address type errors and warnings as this PR correctly indicates. In closing, I want to extend gratitude as I understand that it's not a trivial task to refactor the project to make it behave a little better with mypy and other similar type checkers - personally I don't use them, hence why you might have ended up discovering so many errors and linting issues with the current codebase 😅.

rnag avatar Aug 15 '22 16:08 rnag

Hello @rnag!

Since it has been 1y+ from your last comment, and:

  • PR is a step forward
  • PR is not "awfully complicated"

May I suggest merging it (also at least https://github.com/stdedos/dataclass-wizard/commit/2a50fb098798e57667b292d957d41a1bf9cac221#diff-848eae7420b3910167674508afab5eaba80b92ae43fd6bba5ddaea3e787cdf9f) and creating a new alpha/beta/rc/bugfix/minor release out of this?

stdedos avatar Nov 14 '23 11:11 stdedos