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

bug: KeyError when using TypedDict and Unpack #11

Closed
redb0 opened this issue Jul 9, 2024 · 2 comments
Closed

bug: KeyError when using TypedDict and Unpack #11

redb0 opened this issue Jul 9, 2024 · 2 comments
Assignees

Comments

@redb0
Copy link

redb0 commented Jul 9, 2024

The following example throws a KeyError exception

# test.py
from typing import TypedDict

from typing_extensions import Unpack


class Options(TypedDict):
    foo: int


class A:
    def __init__(self,**kwargs: Unpack[Options]) -> None:
        self.options = kwargs
import griffe

extensions = griffe.load_extensions(
    "griffe_typingdoc",
)

data = griffe.load("test", extensions=extensions)
print(data)

I use:

  • Python 3.9.19
  • griffe 0.47.0
  • griffe-typingdoc 0.2.5

It seems that the point is that it is trying to find Options inside A, not at the module level (here)

Traceback

Traceback (most recent call last):
  File "/home/projects/sdk/test2.py", line 7, in <module>
    data = griffe.load("test", extensions=extensions)
  File "/home/projects/virtualens/SF8d8bN-py3.9/lib/python3.9/site-packages/griffe/loader.py", line 807, in load
    result = loader.load(
  File "/home/projects/virtualens/SF8d8bN-py3.9/lib/python3.9/site-packages/griffe/loader.py", line 233, in load
    self.extensions.call("on_package_loaded", pkg=top_module)
  File "/home/projects/virtualens/SF8d8bN-py3.9/lib/python3.9/site-packages/griffe/extensions/base.py", line 346, in call
    getattr(extension, event)(**kwargs)
  File "/home/projects/virtualens/SF8d8bN-py3.9/lib/python3.9/site-packages/griffe_typingdoc/_extension.py", line 125, in on_package_loaded
    self._handle_object(pkg)
  File "/home/projects/virtualens/SF8d8bN-py3.9/lib/python3.9/site-packages/griffe_typingdoc/_extension.py", line 110, in _handle_object
    self._handle_object(member)  # type: ignore[arg-type]
  File "/home/projects/virtualens/SF8d8bN-py3.9/lib/python3.9/site-packages/griffe_typingdoc/_extension.py", line 110, in _handle_object
    self._handle_object(member)  # type: ignore[arg-type]
  File "/home/projects/virtualens/SF8d8bN-py3.9/lib/python3.9/site-packages/griffe_typingdoc/_extension.py", line 112, in _handle_object
    self._handle_function(obj)  # type: ignore[arg-type]
  File "/home/projects/virtualens/SF8d8bN-py3.9/lib/python3.9/site-packages/griffe_typingdoc/_extension.py", line 65, in _handle_function
    other_params_section := module._other_parameters_docs(func, node=node),
  File "/home/projects/virtualens/SF8d8bN-py3.9/lib/python3.9/site-packages/griffe_typingdoc/_static.py", line 131, in _other_parameters_docs
    typed_dict = annotation.slice.parent.get_member(annotation.slice.name)  # type: ignore[attr-defined]
  File "/home/projects/virtualens/SF8d8bN-py3.9/lib/python3.9/site-packages/griffe/mixins.py", line 78, in get_member
    return self.members[parts[0]]  # type: ignore[attr-defined]
KeyError: 'Options'
@pawamoy
Copy link
Member

pawamoy commented Jul 9, 2024

Hi @redb0, thanks for the report. Looks like you're right! I'll fix this asap (PRs welcome too). Ideally we should resolve the name in the slice, then obtain it from the modules_collection.

pawamoy added a commit that referenced this issue Sep 10, 2024
… from the parent of the function being handled

Issue-11: #11
@pawamoy
Copy link
Member

pawamoy commented Sep 10, 2024

Should be fixed in v0.2.7, thanks for your patience.

@pawamoy pawamoy closed this as completed Sep 10, 2024
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

2 participants