Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CrossHair dies on arguments with PEP604 Unions (e.g. "int|str") #161

Closed
pschanely opened this issue Apr 7, 2022 · 1 comment
Closed

Comments

@pschanely
Copy link
Owner

We expect a counterexample of "hi" here, but get an error instead.

There may be some related issues around these unions; note that typing_inspect does not yet understand them: ilevkivskyi/typing_inspect#83

(ch_310) phillips-air:~ pschanely$ python -V
Python 3.10.0
(ch_310) phillips-air:~ pschanely$ cat foo.py
from typing import Union

def either(thing: (int|str)) -> (int|str):
    '''
    post: __return__ != "hi"
    '''
    return thing
(ch_310) phillips-air:~ pschanely$ crosshair check foo.py
Traceback (most recent call last):
  File "/Users/pschanely/miniconda3/envs/ch_310/bin/crosshair", line 33, in <module>
    sys.exit(load_entry_point('crosshair-tool', 'console_scripts', 'crosshair')())
  File "/Users/pschanely/proj/CrossHair/crosshair/main.py", line 658, in main
    sys.exit(unwalled_main(cmd_args))
  File "/Users/pschanely/proj/CrossHair/crosshair/main.py", line 608, in unwalled_main
    return check(args, options, sys.stdout, sys.stderr)
  File "/Users/pschanely/proj/CrossHair/crosshair/main.py", line 581, in check
    for message in run_checkables(analyze_any(entity, options)):
  File "/Users/pschanely/proj/CrossHair/crosshair/core.py", line 708, in run_checkables
    collector.extend(checkable.analyze())
  File "/Users/pschanely/proj/CrossHair/crosshair/core.py", line 639, in analyze
    analysis = analyze_calltree(options, conditions)
  File "/Users/pschanely/proj/CrossHair/crosshair/core.py", line 980, in analyze_calltree
    call_analysis = attempt_call(
  File "/Users/pschanely/proj/CrossHair/crosshair/core.py", line 1188, in attempt_call
    bound_args = gen_args(conditions.sig) if bound_args is None else bound_args
  File "/Users/pschanely/proj/CrossHair/crosshair/core.py", line 586, in gen_args
    value = proxy_for_type(param.annotation, smt_name, allow_subtypes)
  File "/Users/pschanely/proj/CrossHair/crosshair/core.py", line 549, in proxy_for_type
    return proxy_for_class(typ, varname)
  File "/Users/pschanely/proj/CrossHair/crosshair/core.py", line 388, in proxy_for_class
    data_members = get_type_hints(typ)
  File "/Users/pschanely/miniconda3/envs/ch_310/lib/python3.10/typing.py", line 1827, in get_type_hints
    raise TypeError('{!r} is not a module, class, method, '
TypeError: int | str is not a module, class, method, or function.
@pschanely
Copy link
Owner Author

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

No branches or pull requests

1 participant