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

TypeError: Class.__init__() got an unexpected keyword argument 'index_signatures' #16

Closed
adaxi opened this issue Oct 4, 2024 · 1 comment

Comments

@adaxi
Copy link

adaxi commented Oct 4, 2024

If you take the reproducer in #2 and edit the sdk/src/index.ts file to include:

export interface SourceField {
  label?: string
  value?: string | number | boolean
}

export class C1 {
  [key: string]: SourceField
}

export interface C2 {
  [key: string]: SourceField
}

class B <T> {
  t: T
  constructor(t: T) {
    this.t = t
  }
  [key: string]: any
  sourceFields?: C1
  sourceFields2?: C2
}

export interface Equal<T> {
  isEqual(other: T): boolean
  isSame(other: T): boolean
}

export interface Serializable<T> {
  serialize(): T
}

export interface Updatable<T> {
  update(other: T): T
}

export type Cachable<T, K> = Equal<T> & Serializable<K> & Updatable<T>

export interface CacheCountable {
  incrementCacheCounter(): void
  decrementCacheCounter(): void
  getCacheCounter(): number
}

/**
 * @class 
 */
export class C extends B<string> implements C2, CacheCountable , Cachable<string, C> {
  _y?: number
  set y (x: number) {
    this.y = x
  }
  public u: C

  constructor() {
    super('1')
    this.u = this
  }

  isEqual() {return false}
  isSame() { return true }
  update(other: string) {return other}
  serialize(){ return this }
  incrementCacheCounter() {}
  decrementCacheCounter() {}
  getCacheCounter() { return 1 }
}

You get the following error:

INFO    -  Cleaning site directory
INFO    -  Building documentation to directory:
           /home/gbo/Workspaces/reproducer/docs/site
INFO    -  griffe_typedoc: JSON written to /tmp/tmpuzrr3g69
ERROR   -  Error reading page 'index.md': Class.__init__() got an
           unexpected keyword argument 'index_signatures'
Traceback (most recent call last):
  File "/home/gbo/Workspaces/reproducer/docs/.venv/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/mkdocs/__main__.py", line 288, in build_command
    build.build(cfg, dirty=not clean)
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/mkdocs/commands/build.py", line 310, in build
    _populate_page(file.page, config, files, dirty)
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/mkdocs/commands/build.py", line 167, in _populate_page
    page.render(config, files)
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/mkdocs/structure/pages.py", line 285, in render
    self.content = md.convert(self.markdown)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/markdown/core.py", line 357, in convert
    root = self.parser.parseDocument(self.lines).getroot()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/markdown/blockparser.py", line 117, in parseDocument
    self.parseChunk(self.root, '\n'.join(lines))
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/markdown/blockparser.py", line 136, in parseChunk
    self.parseBlocks(parent, text.split('\n\n'))
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/markdown/blockparser.py", line 158, in parseBlocks
    if processor.run(parent, blocks) is not False:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/mkdocstrings/extension.py", line 128, in run
    html, handler, data = self._process_block(identifier, block, heading_level)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/mkdocstrings/extension.py", line 216, in _process_block
    data: CollectorItem = handler.collect(identifier, options)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/mkdocstrings_handlers/typescript/handler.py", line 124, in collect
    data = load_typedoc(["typedoc"])
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/griffe_typedoc/loader.py", line 59, in load
    return json.load(tmpfile, cls=TypedocDecoder)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/__init__.py", line 293, in load
    return loads(fp.read(),
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/__init__.py", line 359, in loads
    return cls(**kw).decode(s)
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/griffe_typedoc/decoder.py", line 542, in _object_hook
    return _loader_map[kind](obj_dict, self._symbol_map)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/griffe_typedoc/decoder.py", line 69, in wrapper
    obj = func(obj_dict)
          ^^^^^^^^^^^^^^
  File "/home/gbo/Workspaces/reproducer/docs/.venv/lib/python3.11/site-packages/griffe_typedoc/decoder.py", line 124, in _load_class
    return Class(**obj_dict)
           ^^^^^^^^^^^^^^^^^
TypeError: Class.__init__() got an unexpected keyword argument 'index_signatures'

I believe this reproducer hides multiple errors, I have also the same error for interface, and I was also having: 'ValueError: 'intersection' is not a valid TypeKind'

@pawamoy
Copy link
Member

pawamoy commented Oct 5, 2024

Fixed in griffe-typedoc 0.0.0.0.2.7 and mkdocstrings-typescript 0.0.1.0.3.2

@pawamoy pawamoy closed this as completed Oct 5, 2024
pawamoy added a commit to mkdocstrings/griffe-typedoc that referenced this issue Mar 9, 2025
pawamoy added a commit that referenced this issue Mar 24, 2025
Issue-mkdocstrings/typescript#16: #16
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