Skip to content

[pywin32] replace Incomplete win32print types#15794

Open
MaxTheWhale wants to merge 2 commits into
python:mainfrom
MaxTheWhale:win32print-improvements
Open

[pywin32] replace Incomplete win32print types#15794
MaxTheWhale wants to merge 2 commits into
python:mainfrom
MaxTheWhale:win32print-improvements

Conversation

@MaxTheWhale
Copy link
Copy Markdown

Hello, first time contributor so feel free to let me know if I'm doing anything wrong!

This PR fixes all the Incomplete types in the win32print module of the pywin32 package. The majority of the diff comes from defining TypedDict classes for all the Windows API types (e.g. PRINTER_INFO_2), and then adding several overloads to select the correct types for each function.

I also included a commit to add missing types to pywintypes that I noticed whilst working on the printing types, see the commit message for more details.

I haven't raised or linked this to an issue yet, let me know if I should do so.

Thanks in advance!

This commit contains the following changes:
- Add the missing `DEVMODEType` and `DEVMODEWType` types, these are
  both aliases to the `PyDEVMODEW` class.
- Merge the `PyDEVMODE` and `PyDEVMODEW` classes, these are the same
  class in reality.
- Fix the type of `TimeType.format` to include the default value for
  the `format` parameter.
This commit audits all the types in the win32print module, replacing all
`Incomplete` types with an appropriate `TypedDict`, and using overloads
to reference the correct version of the type. The types for the
win32print module should now be complete and accurate as far as I can
tell.
@github-actions
Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau
Copy link
Copy Markdown
Collaborator

srittau commented May 18, 2026

This PR fixes all the Incomplete types in the win32print module of the pywin32 package. The majority of the diff comes from defining TypedDict classes for all the Windows API types (e.g. PRINTER_INFO_2), and then adding several overloads to select the correct types for each function.

Not a full review, just something I noticed: I assume that these typed dicts don't exist at runtime? In that case, the names need to be prefixed with _ and be decorated with @type_check_only (from typing). We should also use PEP 8 names for these typed dicts. So, instead of e.g.

class PRINTER_INFO_1(TypedDict):

use

@type_check_only
def _PrinterInfo1(TypedDict):

@MaxTheWhale
Copy link
Copy Markdown
Author

use

@type_check_only
def _PrinterInfo1(TypedDict):

Hi @srittau, thanks for taking a look! Indeed, all these typed dicts don't exist at runtime.

When I add this, I get flake8 failures such as:

stubs/pywin32/_win32typing.pyi:253:1: Y049 TypedDict "_PrinterInfo3" is not used

Any idea the best approach here? I believe whoever set up these stubs intended the entire _win32typing file to be private.

@srittau
Copy link
Copy Markdown
Collaborator

srittau commented May 19, 2026

Good point, I missed that. In that case, we don't need the prefix, which should fix the warning. @type_check_only and the naming convention should be applied, though.

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 this pull request may close these issues.

2 participants