Commit Graph

23984 Commits

Author SHA1 Message Date
toofar d9a46b1a62 explicitly exclude pyright config from manifest 2022-10-29 15:14:16 +13:00
toofar 97920c8271 Configure pyright to look at PyQt5 imports.
Define some constants for pyright to control how it handles the imports
in qutebrowser.qt.*

This is mainly for autocompletion and definitions with VS Code, which
uses pyright via the pylance extension. If you have multiple possible
places something could be imported from, and one of them isn't
installed, the type of the thing being imported will fall back to Any,
and you wont get nice things.
So we use this file to make sure only certain imports are configured.

The most important thing to remember about this file is it'll control
where type definitions come from in VS Code. You can have multiple
backends defined as true, generally the last import will win in that
case. If any of the enabled imports aren't installed though you may not
get any type hints at all.

PyQt5 has been configured for now to match the type checking configured
in CI.
Personally I would be fine with PyQt6 configured here anyway since
that's generally what we are developing against these days.

See #7370 for more info.
2022-10-29 15:08:48 +13:00
Florian Bruhin 9c17f9d9b3
Merge pull request #7406 from qutebrowser/chore/docs_about_mypy
doc: add some contributor notes about mypy
2022-10-26 09:26:19 +02:00
toofar 819d56043b doc: add some contributor notes about mypy
also update the default tox env list which I forgot to do when changing
the mypy targets.
2022-10-14 15:49:28 +13:00
Florian Bruhin 5e11e6c7d4 mypy: Remove unneeded int(...)
Follow-up to 377bdf736f - less confusing
that way IMHO, as the value now is already an int in that branch.
2022-09-16 15:00:19 +02:00
Florian Bruhin 8164157072 mypy: Make VENDORED_SIP private
Follow-up to 76ca4a9dd6.
2022-09-16 15:00:19 +02:00
Florian Bruhin fc4fd5f6b0 mypy: Use cast instead of ignore for QKeySequence
Follow-up to 3d93e15378
2022-09-16 15:00:19 +02:00
Florian Bruhin 77facc8001 mypy: Use Union instead of ignore 2022-09-16 15:00:19 +02:00
Florian Bruhin 2d4fe87075 mypy: Use annotation instead of assert
Follow-up to 9c193c18f0
2022-09-16 15:00:19 +02:00
Florian Bruhin 6ef015bfd8 mypy: Move around some comments 2022-09-16 15:00:19 +02:00
Florian Bruhin 6f9fda9b6e mypy: Make type for _PREFERRED_COLOR_SCHEME_DEFINITIONS more concrete
Follow-up to b0e3dcef81.
2022-09-16 15:00:14 +02:00
Florian Bruhin 74027d3395 Drop certificateerror.create factory function
Now that the two implementations are in the same class, there's no need
for the indirection anymore.

Follow-up to 647b74197a.
2022-09-16 14:34:27 +02:00
Florian Bruhin 91672cc822 mypy: Simplify handling in show_dialog
The problem here is that mypy (correctly) complains that self._dialog
could be None again at the point that the lambda runs, which is a
different variable scope.

The assert can be dropped (in the show_dialog locals scope, mypy *knows*
it's never None, as we just assigned it!).

Follow-up to 1bbf75ae7d.
2022-09-16 14:29:34 +02:00
Florian Bruhin 8dd2bd5b54 tox: Use more unique env var name
(Ab)using an environment variable indeed seems like the easiest way
forward here, but since it is exposed in the environment for the called
processes, let's give it a name which is less likely to clash, and more
easily identifyable.

Follow-up to c1738ca550.
2022-09-16 14:26:33 +02:00
Florian Bruhin 46ebef5644 mypy: Use tox.ini to install PyQt6 conditionally
The changes in requirements-mypy.txt would get overwritten on the next
dependency update. Also, it looks like we don't actually need PyQt6 (or
the PyQt6 stubs) available for checking PyQt 5 code if all Qt 6 imports
are appropriately gated by conditionals mypy knows about.

Follow-up to c1738ca550.
2022-09-16 14:13:50 +02:00
toofar f0bfc9aab2 Document how to set the backend for the tests.
I only had the old way save in my bash history and this one was only
mentioned in the changelog.

Also changed the heading above the new entry to be title case, which
seems to be more consistent with the other headinfs in the file.

Also remove the one remaining mention of `QUTE_BDD_WEBENGINE` since it
does nothing anymore.
2022-09-16 17:13:52 +12:00
toofar e50bc92e9a remove leftover compiled requirements files
Leftover from 62515fecf0a64f ref #7091
2022-09-16 17:13:05 +12:00
toofar be5b4c5dd0
Merge pull request #7392 from qutebrowser/feat/turn_on_mypy_pyqt5
Get mypy working, with pyqt5, on qt6-v2 branch
2022-09-16 16:58:49 +12:00
toofar 71e9b9d854 fix lint: qt5 vs qt6 confusion 2022-09-11 17:31:52 +12:00
toofar 4b3ec40eb0 mypy: re-enable CI jobs for pyqt5
We'll be going forward with type checking on PyQt5 for now while
figuring out what to do with PyQt6 type checking.

See https://github.com/qutebrowser/qutebrowser/discussions/7372#discussioncomment-3502200
2022-09-11 17:31:52 +12:00
toofar 377bdf736f mypy: fix qenum debug type hints?
1. stop pretending to propagate None to the qt/python debug methods
2. handle simplewrapper in extract_enum_val

I think this stuff will need a little more cleaning up when we get to
sorting out type checking on PyQt6.

The whole key debug module seems to be a bit fuzzy about when it's going
to be passing around a simplewrapper, int and enum.

I believe we are using sip.simplerwapper as a common parent type of all
the Qt Flag/Enum values. I think it gets better on PyQt6, don't remember
though. It might just change to be sip.wrapper instead.
2022-09-11 17:22:51 +12:00
toofar 3d93e15378 mypy: add hints and comments around QKeySequence
Mypy doesn't seem to know that QKeySequence is an iterable, so it
complains about itertools not handling it. And since we lose type
information there we have to add it back in a couple of places.
2022-09-11 17:22:50 +12:00
toofar 2eacf0456a mypy: defer to machinery for conditional: QKeyCombination
That wasn't so hard, just put everything behind compile time constants,
even the type definition.
2022-09-11 17:22:50 +12:00
toofar ed13c3c734 mypy: ignores for another enum: KeyboardModifier
There are several cases where PyQt5 methods expects the plural flags version but
we've got the singular Enum version from accessing enum members directly.
It's not easy to turn those enums into flags and the flags don't even
exist in PyQt6.
2022-09-11 17:22:50 +12:00
toofar baeb05d6a2 mypy: handle none case in Optional: downloads.reply
I'm not sure how theoretical this case is. There is a comment somewhere
else indicating the reply can "disappear".
2022-09-11 17:22:50 +12:00
toofar b0e3dcef81 mypy: add type hint for defs in darkmode.py
Not sure why mypy was failing to see the inner dicts in
_PREFERRED_COLOR_SCHEME_DEFINITIONS where being seen as "object" by mypy
and not dict, I think the syntax is correct.
Add some basic type hints to help it.
They Any is because usertype.UNSET() is a sentinal object
2022-09-11 17:22:50 +12:00
toofar 9c193c18f0 mypy: cast to subtype: WebEnginePrinting 2022-09-11 17:22:50 +12:00
toofar 046244b54d mypy: defer to machinery for conditional: QWebEngineScripts 2022-09-11 17:22:50 +12:00
toofar 3e9fd4ed7e mypy: defer to machinery for conditional: printing 2022-09-11 17:22:50 +12:00
toofar 52c3caaa05 mypy: Add Optional hint to inspector._settings 2022-09-11 17:22:50 +12:00
toofar 802dc459dc mypy: defer to machinery for conditional: inspector API 2022-09-11 17:22:50 +12:00
toofar aef684cbff mypy: defer to machinery for conditional: webview.certError 2022-09-11 17:22:50 +12:00
toofar 7a2c41c785 mypy: access our tab_bar implementation, not tabBar
Apparently this got changed by the scripts/dev/rewrite_enums.py script?
Strange. 0877fb0d78
2022-09-11 17:22:50 +12:00
toofar b64fdfc584 mypy: ignore enum argument type: UrlFormattingOption
The docs say:

> The options from QUrl::ComponentFormattingOptions are also possible.

> The FormattingOptions type is a typedef for QFlags<UrlFormattingOption>. It stores an OR combination of UrlFormattingOption values.

Maybe we should be should be definining out own types for some of the
enums that include both the QFlag, enum and any child enums.
2022-09-11 17:22:50 +12:00
toofar 1bbf75ae7d mypy: add Optional hint to QPrintDialog 2022-09-11 17:22:50 +12:00
toofar 77a90cab1e mypy: ignore enum binary operator: Qt.WindowType
They are the same damn thing: https://doc.qt.io/qt-6/qt.html#WindowType-enum
2022-09-11 17:22:50 +12:00
toofar 3fae736777 mypy: fix exec() type hints?: prompt
PyQt5 stubs require a flags object that doesn't exist in PyQt6
2022-09-11 17:22:50 +12:00
toofar 5be5b6bb41 mypy: defer to machinery for conditional: QDownloadItem 2022-09-11 17:22:50 +12:00
toofar db8cb25bd3 mypy: ignore enum binary operator: UrlFormattingOption
Yet another case of confusion between flags and enum objects.
2022-09-11 17:22:50 +12:00
toofar a70954a65f mypy: fix KeyboardModifier type in webelem?
Conditionally define a type so it can work with PyQt5s mismatch of enums
and flags and PyQt6s enums.
2022-09-11 17:22:50 +12:00
toofar 5293009413 mypy: defer to machinery for conditional: QOpenGLVersionProfile 2022-09-11 17:22:50 +12:00
toofar 04f1ae74bd mypy: defer to machinery for conditional: qWebEngineVersion 2022-09-11 17:22:50 +12:00
toofar fda08527f1 mypy: defer to machinery for conditional: QVariant 2022-09-11 17:22:50 +12:00
toofar 647b74197a mypy: move conditionals for CertificateErrorWrapper into class
Get rid of the per-backend classes and move the backend specific
conditionals into a common class.

Sadly it seems mypy isn't clever enough to reason ignore a class it should
know is never used. Possibly it looks at them at parse time. Probably putting
the whole class definitions into conditionals would do it but I'm not sure if
I want to go down that route for such a small example. Hopefully there aren't
too many more of these.
2022-09-11 17:22:50 +12:00
toofar 9e1dfacef7 mypy: defer to machinery for conditional: QtSql bound values
Also turn the qt5 value into a list instead of a dict_values, for the
sake of mypy
2022-09-11 17:22:50 +12:00
toofar 42d3cca794 mypy: fallback sqlite error code can be str 2022-09-11 17:22:50 +12:00
toofar e76a063e63 mypy: defer to machinery for conditional: QLibraryInfo 2022-09-11 17:22:50 +12:00
toofar 56822836c5 mypy: fix exec() type hints?
PyQt5 exposes Enums and their corresponding QtFlags objects seperately,
and for some reason they aren't interchangeable. ref https://github.com/python-qt-tools/PyQt5-stubs/issues/142

We could handle this by casting values back and forth between the enum
value (for working with) and the flags value (for passing to methods),
but this situation doesn't even exist with PyQt6, you can use everything
as enums just fine.
So I'm just adding ignore comments and making type definitions
conditional.

Not sure if this is the right thing to be doing or not.

for b3cdb28d044
2022-09-11 17:22:50 +12:00
toofar 4647125172 mypy: fix hints for abstract cert error wrapper 2022-09-11 10:32:07 +12:00
toofar 76ca4a9dd6 mypy: handle sip conditional imports
Putting ignore[type] on the second import works fine. But if we have it
on both the pyqt5 and pyqt6 branch it'll complain about the other branch
on each run. So pull it out to a common place we can ignore.
2022-09-11 10:27:11 +12:00