Skip to content

codespell fails to run on linux with version 2.3.0 #3545

Description

@boralyl

I recently upgraded my pre-commit hook version from 2.2.6 -> 2.3.0 and get a ValueError when running:

Traceback (most recent call last):
  File "/home/runner/.cache/pre-commit/repo3sgkbuvg/py_env-python3.9/bin/codespell", line 5, in <module>
    from codespell_lib import _script_main
  File "/home/runner/.cache/pre-commit/repo3sgkbuvg/py_env-python3.9/lib/python3.9/site-packages/codespell_lib/__init__.py", line 1, in <module>
    from ._codespell import _script_main, main
  File "/home/runner/.cache/pre-commit/repo3sgkbuvg/py_env-python3.9/lib/python3.9/site-packages/codespell_lib/_codespell.py", line 28, in <module>
    from ctypes import wintypes
  File "/home/runner/.local/share/uv/python/cpython-3.9.0-linux-x86_64-gnu/lib/python3.9/ctypes/wintypes.py", line 20, in <module>
    class VARIANT_BOOL(ctypes._SimpleCData):
ValueError: _type_ 'v' not supported

This error looks reasonable as you can't import wintypes on linux:

Python 3.9.0 (default, Oct 20 2020, 07:41:32) 
[Clang 11.0.0 ] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import wintypes
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/aaron/.local/share/uv/python/cpython-3.9.0-linux-x86_64-gnu/lib/python3.9/ctypes/wintypes.py", line 20, in <module>
    class VARIANT_BOOL(ctypes._SimpleCData):
ValueError: _type_ 'v' not supported

It looks like this was introduced when adding support for ANSI colors on windows: #3259

Activity

  1. DimitriPapadopoulos commented on Sep 18, 2024

    @DimitriPapadopoulos
    Collaborator

    It works for me:

    $ python
    Python 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 
    >>> from ctypes import wintypes
    >>> 

    Could it be an issue with this specific deployment of Python? How did you install Python?

    Where is it documented that you cannot import wintypes from Linux? The ctypes documentation merely states:

    The ctypes.wintypes module provides quite some other Windows specific data types, for example HWND, WPARAM, or DWORD. Some useful structures like MSG or RECT are also defined.

  2. changed the title [-]codespellfails to run on linux with version 2.3.0[/-] [+]codespell fails to run on linux with version 2.3.0[/+] on Sep 18, 2024
  3. DimitriPapadopoulos commented on Sep 18, 2024

    @DimitriPapadopoulos
  4. DimitriPapadopoulos commented on Sep 18, 2024

    @DimitriPapadopoulos
    Collaborator

    The patch to allow wintypes to be imported on non-Windows systems is relatively recent:
    python/cpython#60600
    python/cpython#21394

    It has been applied to Python branches 3.8 and 3.9, which means it might be missing from Python 3.9.0. But then why use Python 3.9.0 instead of 3.9.20?

  5. DimitriPapadopoulos commented on Sep 18, 2024

    @DimitriPapadopoulos
    Collaborator

    Does #3546 help in your case?

  6. boralyl commented on Sep 18, 2024

    @boralyl
    Author

    The patch to allow wintypes to be imported on non-Windows systems is relatively recent: python/cpython#60600 python/cpython#21394

    It has been applied to Python branches 3.8 and 3.9, which means it might be missing from Python 3.9.0. But then why use Python 3.9.0 instead of 3.9.20?

    Thank you, I didn't notice that github actions was using 3.9.0 instead of the latest version of 3.9.x. That was due to an error in how I defined the python version. You are correct, using the latest 3.9.x version works fine.

  7. boralyl commented on Sep 18, 2024

    @boralyl
    Author

    Does #3546 help in your case?

    I can try this out later today if you think it's still relevant

  8. DimitriPapadopoulos commented on Sep 18, 2024

    @DimitriPapadopoulos
    Collaborator

    It's still relevant, if only to avoid importing ctypes.wintypes when it's not needed, on non-Windows platforms.

  9. boralyl commented on Sep 19, 2024

    @boralyl
    Author

    Does #3546 help in your case?

    Confirmed when I use python 3.9.0, it runs as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions