beeware / briefcase

Tools to support converting a Python project into a standalone native application.
https://briefcase.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
2.69k stars 375 forks source link

[Winforms] `collections.abc.ABCMeta` is not available in Toga on `Winforms` #2067

Closed Mause closed 3 days ago

Mause commented 4 days ago

Describe the bug

ERROR tests\hardware\test_location.py::test_current_location - ImportError: cannot import name 'abstractmethod' from 'collections.abc' (C:\Users\me\toga\testbed\build\testbed\windows\app\src\python311.zip\collections\abc.pyc)

Steps to reproduce

Try to import collections.abc.ABCMeta on Winforms in the briefcase toga testbed

Expected behavior

The import is successful

Screenshots

No response

Environment

Logs

Additional context

No response

freakboy3742 commented 3 days ago

Thanks for the report.

It turns out that ABCMeta isn't technically part of collections.abc; it's abc.ABCMeta. It is importable as collections.abc.ABCMeta on Python3.13, as a result of some changes to how the collections.abc module is defined - but that effectively relies on an import side effect (the sort of thing that __all__ exists to override)

So - the question then becomes "how did this manifest?" An error generated by from collections.abc import ABCMeta is correct - that's not where it should be imported from... but I can't find any instance of this in the existing code. How did this manifest in practice for you?

mhsmith commented 3 days ago

Specifically, this error happens on Python 3.12 but not Python 3.13:

% python3.12 -c 'from collections.abc import abstractmethod'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: cannot import name 'abstractmethod' from 'collections.abc' (/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/collections/abc.py)
% python3.13 -c 'from collections.abc import abstractmethod'
%

But CI runs the testbed on Python 3.12, so if there was such an import, we should already have discovered it.

@Mause: I think you must have modified the code to add this invalid import. The fix is to change collections.abc to simply abc.

If that's not the case, please explain what you did in more detail, and we'll reopen the issue.

Mause commented 3 days ago

Ah, this was definitely user error on my part then, I was looking to add an abstract class as part of the probe/location implementation I was writing, and my memory conflated collections.abc and abc

Sorry 'bout the confusion Russ!