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

Error handling attrs.define when imported locally #1571

Closed
gmacon opened this issue Jan 25, 2024 · 0 comments
Closed

Error handling attrs.define when imported locally #1571

gmacon opened this issue Jan 25, 2024 · 0 comments
Assignees
Labels
bug cat: stubs and 3p type stubs and third-party types

Comments

@gmacon
Copy link

gmacon commented Jan 25, 2024

With pytype 2024.01.05 on Python 3.8, this input:

from attrs import define

@define
class C:
    pass

produces this output from pytype-single --output - repro.py:

Traceback (most recent call last):
  File ".../bin/pytype-single", line 8, in <module>
    sys.exit(main())
  File ".../lib/python3.8/site-packages/pytype/single.py", line 87, in main
    return _run_pytype(options)
  File ".../lib/python3.8/site-packages/pytype/single.py", line 98, in _run_pytype
    return io.process_one_file(options)
  File ".../lib/python3.8/site-packages/pytype/io.py", line 77, in wrapper
    return f(*args, **kwargs)
  File ".../lib/python3.8/site-packages/pytype/io.py", line 226, in process_one_file
    ret = check_or_generate_pyi(options, loader)
  File ".../lib/python3.8/site-packages/pytype/io.py", line 77, in wrapper
    return f(*args, **kwargs)
  File ".../lib/python3.8/site-packages/pytype/io.py", line 169, in check_or_generate_pyi
    errorlog, result, ast = generate_pyi(
  File ".../lib/python3.8/site-packages/pytype/io.py", line 123, in generate_pyi
    ret = _call(analyze.infer_types, src, options, loader, ctx=ctx)
  File ".../lib/python3.8/site-packages/pytype/io.py", line 77, in wrapper
    return f(*args, **kwargs)
  File ".../lib/python3.8/site-packages/pytype/io.py", line 88, in _call
    return analyze_types(
  File ".../lib/python3.8/site-packages/pytype/analyze.py", line 121, in infer_types
    ast = ctx.vm.compute_types(defs)
  File ".../lib/python3.8/site-packages/pytype/tracer_vm.py", line 758, in compute_types
    self.pytd_for_types(defs),
  File ".../lib/python3.8/site-packages/pytype/tracer_vm.py", line 641, in pytd_for_types
    d = option.to_pytd_def(self.ctx.exitpoint, name)
  File ".../lib/python3.8/site-packages/pytype/abstract/_base.py", line 234, in to_pytd_def
    return self.ctx.pytd_convert.value_to_pytd_def(node, self, name)
  File ".../lib/python3.8/site-packages/pytype/output.py", line 461, in value_to_pytd_def
    md = metadata.to_pytd(v.to_metadata())
  File ".../lib/python3.8/site-packages/pytype/overlays/attr_overlay.py", line 231, in to_metadata
    "init": self._current_args["init"],
TypeError: 'NoneType' object is not subscriptable
File: repro.py

Changing the input to

import attrs

@attrs.define
class C:
    pass

works:

import attr
import attrs

@attr.s
class C:
    def __init__(self) -> None: ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cat: stubs and 3p type stubs and third-party types
Projects
None yet
Development

No branches or pull requests

2 participants