Replies: 4 comments 1 reply
-
It should also be noted that some warnings would be impossible to mitigate right now to my knowledge. For example accessing properties that we load from the UI files. There will always be warnings that |
Beta Was this translation helpful? Give feedback.
-
I created an example of what a fully type-hinted file might look like. This resolved all the warnings basedPyright was throwing at me: sonic2kk@e5f79d7 This doesn't have any PEP or line-length flags though. I imagine if we start including those the structure of the file to begin to look very different. |
Beta Was this translation helpful? Give feedback.
-
Interesting discussion. I once ran
I feel like doing it per "type of change" makes sense if applicable. Otherwise per-file is okay I guess.
I think it depends a bit. There are some places where the types can't break much.
I guess both putting it into CONTRIBUTING.md and adding tests makes sense in the long term.
Yes, that is something we need to consider. We cannot type objects with dynamic attributes...
POSSIBLE_STEAM_INSTALL_LOCATIONS: list[dict[str, str]] = [
{
'install_dir': f'{_STEAM_ROOT}/compatibilitytools.d/',
'display_name': 'Steam',
'launcher': 'steam',
... That is a good example for the "dictionary typing".
That's another thing. I wonder if we should enforce tools like pep8 or black. |
Beta Was this translation helpful? Give feedback.
-
In #437 I noted that one potential warning we can run into with checkers is when we ignore functions that return a value. This happens sometimes with functions that we created (such as with dbusutil), but also happens in situations where we probably don't care, such as when writing to files - The recommended solution is to assign the result of the call to I think this is a potential case where we might want to keep this, but demote it to a warning / equivalent rather than an angry error. Something we can encourage to be displayed but only handle it on a case-by-case basis. It might become overly noisy to use |
Beta Was this translation helpful? Give feedback.
-
I didn't open this as an issue as this is more of a general question. There may be more pressing things, of course, but I think opening Discussions is more for general chat around a broad idea rather than a more focused "enhancement" issue.
ProtonUp-Qt uses Python's type-hinting a bit sporadically. And because the project has been around for a little while and targetted a few different Python versions, some of the codebase is still using the older typing syntax with
from typing import Dict, List
etc. Now, we target Python 3.10, and I think we discussed before about moving the codebase over gradually to use the newer syntax where we can (i.e. usingfoo: list
instead offoo: List
. However, this comes with a challenge. Many linters when you type with a list will want you to explicitly type the list, dict, etc. But on the other hand, this syntax is deprecated in Python 3.9. I did open one PR to resolve one instance of this (#416).I have recently began using a linter called basedPyright, which is very strict by default in particular with typing (to the point of wanting explicitly typed dicts). It can however be configured to be less-strict, i.e. we can disable certain warnings or reduce some down to warnings in cases where we think certain warnings can be useful in some circumstances but are too much effort to work around in others without specific code changes. Keeping these as warnings means we can still keep track of them as "tech debt" that could be resolved as part of a broader change.
Perhaps we could come up with a configuration for what we want to and don't want to lint?
Type hinting in Python can be a bit of a fierce topic, and Python doesn't exactly enforce it (by design iirc, which is part of the fierce debate). But it's not the only linting warning. Certain PEP protocols can be very strict by default such as maximum line length (some projects set a standard inspired by this but not the default which is very restrictive).
So I think the overall purpose of this discussion is to discuss how we want to handle typing and the overall idea of "quality gates" going forward.
list[str]
instead oflist
. We already do this to some degree but not consistently. This also leads to another issue:pycodestyle
. Which type checker and style checker we use, and how strict we want to make them, is certainly a point of discussion.List
withlist
, but typing them might be tricky and create a larger diff. There may also be interconnected dependencies, for example typing a variable that gets assigned a return value of a method, when the method itself is not yet typed.Some of the typing/linting changes can be done ad-hoc in a PR but some, if we decide for example to enforce partially strict type hinting, could require significant changes that might pollute a PRs diff, and those might be better served in their own PR.
If we decide to go forward with this, once things are ironed out and discussed and we have some project guidelines in place, we could put this into a
CONTRIBUTING.md
document.No, this isn't a massively important topic. But ProtonUp-Qt is in a nice spot. I have experience with a project where there is limited opportunity for structure in the codebase and that has partially inspired my proposal for tests and for this. I also partially want to reduce the noise of basedPyright without simply tuning everything to my preferences, I figured if we could get a standard for the project that would work nicely.
And, if this is something you don't think is very valuable to the project, we can close this or shelve it for now if you think it might be a good discussion in the future, but not right now.
Beta Was this translation helpful? Give feedback.
All reactions