Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3.10/pyqt has stricter typing rules #951

Closed
ZLLentz opened this issue Nov 18, 2022 · 5 comments · Fixed by #1080
Closed

Python 3.10/pyqt has stricter typing rules #951

ZLLentz opened this issue Nov 18, 2022 · 5 comments · Fixed by #1080

Comments

@ZLLentz
Copy link
Member

ZLLentz commented Nov 18, 2022

Describe the bug

There are places in pydm where floating-point values are passed into fields that are nominally int in the qt source. This is OK in python 3.9 and earlier, in these cases the values are converted by truncating to the floor.

In Python 3.10, this no longer works.
https://docs.python.org/3/whatsnew/3.10.html#other-language-changes

Builtin and extension functions that take integer arguments no longer accept Decimals, Fractions and other objects that can be converted to integers only with a loss (e.g. that have the int() method but do not have the index() method). (Contributed by Serhiy Storchaka in bpo-37999.)

Any point in the pydm code that passes in a floating point value into a qt int field will break upon upgrading to python 3.10. This is pretty annoying to track down all instances of and isn't a problem unique to pydm, it affects most pyqt-based applications.

Expected behavior

It's not urgent in any sense of the word, but we should work toward python 3.10 compatibility in pydm in a systematic way that makes sure we aren't missing anything.

Steps to Reproduce

Install pydm into a python 3.10 environment and try to use the PyDM drawing widgets, for example. I'm not sure the full scope of which things are affected.

Possible Solution

We should figure out a systemic way to track down instances of this and make sure we pass integer values when they are required by qt. Simplest is copious calls to int but this might not be the best way.

My Platform

rhel7
python 3.10
pydm v1.18.1

@jbellister-slac
Copy link
Collaborator

I've been poking around other pyqt5 based open source projects, and pretty much everything I've seen so far is just converting to int before passing it to qt. I think it's probably the most straightforward way to go about it.

I'll figure out which qt objects are causing problems (QPoint seems the biggest offender) and grep through the codebase for instances that need fixing. It's not looking too terrible yet, but if it gets to be too much I can re-think how to better do it.

@ZLLentz
Copy link
Member Author

ZLLentz commented Jan 31, 2023

If you run into a systematic way to find these, I'd be interested to hear about it- at some point I'll look for it myself. I was thinking about ways to scrape the qt docs for floating point input fields and finding all usages of those in my code...

@jbellister-slac
Copy link
Collaborator

In my brief (unrelated) Qt6 adventure I did find a clever way over here for doing a find/replace of unscoped enum usage involving going through all the pyqt .pyi files : qutebrowser/qutebrowser#5904

I was thinking something similar could be viable for the find part of this task. Haven't stumbled on an existing solution yet, or tried to write my own. Was planning to get back to this later this week. As for what to do with all the found instances I can' think of any good way that doesn't involve manually looking at each one and using int() or switching to the floating point equivalent of the method/object as needed.

canismarko pushed a commit to spc-group/haven that referenced this issue Mar 14, 2023
Type checking became stricter in python 3.10, so pydm doesn't load
some widgets properly.

slaclab/pydm#951
@ZLLentz
Copy link
Member Author

ZLLentz commented May 29, 2024

I ended up using the .pyi files and taking a deep dive into all of the pyqt-related repos that are maintained at SLAC and used by my group, since I'm looking to update my group's Python version in the next few months.

In the end, I only found one module that still has this issue in pydm, the analog indicator. I'll document the behavior and submit a PR that fixes it.

Since this is the only instance I was able to find, I'll also close this issue once that PR is merged.

@canismarko
Copy link

@ZLLentz Thanks for fixing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants