Skip to content

PR: Symmetrize QDateTime.toPython and toPyDateTime, etc.#421

Merged
dalthviz merged 6 commits intospyder-ide:masterfrom
StSav012:symmetrize_QDateTime_to_Python_conversions
Apr 14, 2023
Merged

PR: Symmetrize QDateTime.toPython and toPyDateTime, etc.#421
dalthviz merged 6 commits intospyder-ide:masterfrom
StSav012:symmetrize_QDateTime_to_Python_conversions

Conversation

@StSav012
Copy link
Copy Markdown
Contributor

@StSav012 StSav012 commented Apr 5, 2023

As far as I've noticed, the favorable Qt5 binding was PyQt5, and for Qt6 it's PySide6. They are different in many ways beside the Qt backend. One of the differences is the way to get Python date/time from the Qt one: it's toPyDateTime/toPyDate/toPyTime in PyQt5/6 and one toPython to rule them all in PySide2/6.

To ease the transfer from PyQt5 to PySide6, I propose the expansion of #169. And some tests for the results, as @CAM-Gerlach has suggested in #403 (comment).

@StSav012 StSav012 marked this pull request as ready for review April 5, 2023 08:45
@dalthviz dalthviz added this to the v2.4.0 milestone Apr 6, 2023
@dalthviz dalthviz changed the title Symmetrize QDateTime.toPython and toPyDateTime, etc. PR: Symmetrize QDateTime.toPython and toPyDateTime, etc. Apr 6, 2023
@dalthviz dalthviz requested a review from CAM-Gerlach April 6, 2023 19:33
@StSav012
Copy link
Copy Markdown
Contributor Author

StSav012 commented Apr 7, 2023

What's the failed check? How has it come to that conclusion? I guess it's with conda=Yes.

Should I split the tests into individual functions? I certainly can, but that would decrease the readability of the code, making numerous functions, of which the def lines, the doc strings, and the spaces in between would make the most of the code. Anyway, it's up to you to decide.

Copy link
Copy Markdown
Member

@CAM-Gerlach CAM-Gerlach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to parameterizing the tests, I also suggest doing an isinstance check that py_date has the expected Python type in each case. Thanks!

@CAM-Gerlach
Copy link
Copy Markdown
Member

What's the failed check? How has it come to that conclusion? I guess it's with conda=Yes.

Seems like the coveralls hook status is just misbehaving because the actual run its linked to confirms the status is still the same. Hopefully the next push should fix it.

Should I split the tests into individual functions? I certainly can, but that would decrease the readability of the code, making numerous functions, of which the def lines, the doc strings, and the spaces in between would make the most of the code. Anyway, it's up to you to decide.

As my review suggests, you can instead achieve the same using Pytest's paramertization, which is actually shorter than the existing test code.

Copy link
Copy Markdown
Member

@CAM-Gerlach CAM-Gerlach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM from my side, thanks @StSav012 . @dalthviz ?

@StSav012
Copy link
Copy Markdown
Contributor Author

In addition to parameterizing the tests, I also suggest doing an isinstance check that py_date has the expected Python type in each case.

I'm sorry I forgot to answer this. The point is that the type check is conducted internally in the __eq__ function. These are the fragments of datetime.py (identical for Python 3.7 and 3.11):

  • in datetime.date:
    def __eq__(self, other):
        if isinstance(other, date):
            return self._cmp(other) == 0
        return NotImplemented
  • in datetime.time:
    def __eq__(self, other):
        if isinstance(other, time):
            return self._cmp(other, allow_mixed=True) == 0
        else:
            return NotImplemented
  • in datetime.datetime:
    def __eq__(self, other):
        if isinstance(other, datetime):
            return self._cmp(other, allow_mixed=True) == 0
        elif not isinstance(other, date):
            return NotImplemented
        else:
            return False

@CAM-Gerlach
Copy link
Copy Markdown
Member

Ah, I see—technically, py_date's __eq__ (which gets called first being on the LHS, or if on the RHS would get called if the NotImplemented path is taken in the __eq__ above) could theoretically compare equal with a datetime, etc. without being one. But that's probably mostly hypothetical pedantry on my part.

@StSav012
Copy link
Copy Markdown
Contributor Author

being on the LHS

Oh, indeed. Thanks for the catch. I've added the explicit type checks. This should make the code more clear.

@CAM-Gerlach
Copy link
Copy Markdown
Member

Thanks!

Copy link
Copy Markdown
Member

@dalthviz dalthviz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @StSav012 !

@dalthviz dalthviz merged commit 42afbc8 into spyder-ide:master Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants