-
Notifications
You must be signed in to change notification settings - Fork 0
TypeError raised when creating a Codec for a class with a ClassVar[LiteralString] #10
Copy link
Copy link
Open
Description
Thanks for this library! It's helped me a lot with some repetitive tasks for a project I'm working on.
I did find a bug that I'd like to report, however. Specifically, typelib raises an error when constructing a Codec for a type that has a ClassVar[LiteralString]. This issue occurs with Python 3.13.7 on Windows 10, with typelib 0.2.0.
Here's a stack trace:
File "D:\Code\Contributions\libretro-database\.venv\python313\Lib\site-packages\typelib\py\inspection.py", line 663, in isdatetimetype
return builtins.issubclass(origin(obj), datetime.datetime)
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Code\Contributions\libretro-database\.venv\python313\Lib\site-packages\typelib\marshals\api.py", line 70, in _get_unmarshaller
if check(node.unwrapped): # type: ignore[arg-type]
~~~~~^^^^^^^^^^^^^^^^
File "D:\Code\Contributions\libretro-database\.venv\python313\Lib\site-packages\typelib\marshals\api.py", line 56, in marshaller
context[node.type] = _get_unmarshaller(node, context=context)
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Code\Contributions\libretro-database\.venv\python313\Lib\site-packages\typelib\codecs.py", line 57, in codec
marshal = marshaller or marshals.marshaller(t=t)
~~~~~~~~~~~~~~~~~~~^^^^^
File "D:\Code\Contributions\libretro-database\scripts\igdb.py", line 1359, in <module> (Current frame)
GameTupleCodec: typelib.Codec[tuple[Game, ...]] = typelib.codec(tuple[Game, ...])
~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
File "D:\Code\Contributions\libretro-database\scripts\match.py", line 26, in <module>
from igdb import load_game_file
File "C:\Python313\Lib\runpy.py", line 88, in _run_code
exec(code, run_globals)
File "C:\Python313\Lib\runpy.py", line 198, in _run_module_as_main
return _run_code(code, main_globals, None,
TypeError: issubclass() arg 1 must be a class
And here's a minimal reproduction:
import dataclasses
import typelib
from typing import ClassVar, LiteralString
@dataclasses.dataclass
class Game:
id: int
__table__: ClassVar[LiteralString] = "<hardcoded SQL statement>"
GameTupleCodec: typelib.Codec[tuple[Game, ...]] = typelib.codec(tuple[Game, ...])You can see the full code here. To run it you'll need to install the requirements.txt in that branch, then you can either import igdb.py as a module or run it as a script.
A workaround is to replace the LiteralString with a str.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels