-
-
Notifications
You must be signed in to change notification settings - Fork 66
Open
Description
Breaking example I found in my own usage:
from beartype import beartype
from multiprocessing import Queue
from typing import TypedDict
class SpecialDict(TypedDict):
pass
class Example:
@beartype
def __init__(self, list1: Queue) -> None:
self.list1: Queue[SpecialDict] = list1
q1: Queue[SpecialDict] = Queue()
Example(q1)Now, to my knowledge, nothing about this breaks PEP conformance and I can't do list1: Queue[SpecialDict] because that gives TypeError: 'method' object is not subscriptable.
Error log:
Traceback (most recent call last):
File "/Users/Moosems/Desktop/test.py", line 8, in <module>
class Example:
File "/Users/Moosems/salve/test.py", line 9, in Example
@beartype
^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/beartype/_decor/decorcache.py", line 77, in beartype
return beartype_object(obj, conf)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/beartype/_decor/decorcore.py", line 87, in beartype_object
_beartype_object_fatal(obj, conf=conf, **kwargs)
File "/usr/local/lib/python3.12/site-packages/beartype/_decor/decorcore.py", line 136, in _beartype_object_fatal
beartype_nontype(obj, **kwargs) # type: ignore[return-value]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/beartype/_decor/_decornontype.py", line 182, in beartype_nontype
return beartype_func(obj, **kwargs) # type: ignore[return-value]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/beartype/_decor/_decornontype.py", line 247, in beartype_func
func_wrapper_code = generate_code(bear_call)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/beartype/_decor/wrap/wrapmain.py", line 118, in generate_code
code_check_params = _code_check_args(bear_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/beartype/_decor/wrap/_wrapargs.py", line 334, in code_check_args
reraise_exception_placeholder(
File "/usr/local/lib/python3.12/site-packages/beartype/_util/error/utilerrraise.py", line 138, in reraise_exception_placeholder
raise exception.with_traceback(exception.__traceback__)
File "/usr/local/lib/python3.12/site-packages/beartype/_decor/wrap/_wrapargs.py", line 189, in code_check_args
hint = sanify_hint_root_func(
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/beartype/_check/convert/convsanify.py", line 178, in sanify_hint_root_func
hint = reduce_hint(
^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/beartype/_check/convert/convreduce.py", line 210, in reduce_hint
hint = _reduce_hint_cached(hint, conf, exception_prefix)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/beartype/_util/cache/utilcachecall.py", line 250, in _callable_cached
raise exception
File "/usr/local/lib/python3.12/site-packages/beartype/_util/cache/utilcachecall.py", line 242, in _callable_cached
return_value = args_flat_to_return_value[args_flat] = func(
^^^^^
File "/usr/local/lib/python3.12/site-packages/beartype/_check/convert/convreduce.py", line 367, in _reduce_hint_cached
hint = hint_reducer( # type: ignore[call-arg]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/beartype/_util/hint/pep/utilpepreduce.py", line 96, in reduce_hint_pep_unsigned
die_unless_hint(hint=hint, exception_prefix=exception_prefix)
File "/usr/local/lib/python3.12/site-packages/beartype/_util/hint/utilhinttest.py", line 99, in die_unless_hint
die_unless_hint_nonpep(hint=hint, exception_prefix=exception_prefix)
File "/usr/local/lib/python3.12/site-packages/beartype/_util/hint/nonpep/utilnonpeptest.py", line 203, in die_unless_hint_nonpep
raise exception_cls(
beartype.roar.BeartypeDecorHintNonpepException: Method __main__.Example.__init__() parameter "list1" type hint <bound method BaseContext.Queue of <multiprocessing.context.DefaultContext object at 0x10cc0da30>> either PEP-noncompliant or currently unsupported by @beartype.
Beartype says however that this either breaks PEP compliance or is unsupported. I believe its the latter. Love the project and the work you do!
leycec
Metadata
Metadata
Assignees
Labels
No labels