felix-hilden / sphinx-codeautolink

Automatic links from code examples to reference documentation
https://sphinx-codeautolink.rtfd.io
MIT License
58 stars 9 forks source link

Track subscripts and multi-assignments by analysing nested type hints #20

Open felix-hilden opened 2 years ago

felix-hilden commented 2 years ago

From #5: we have the machinery in place to track subscripts and unpacking assignments by analysing type hints that are nested tuples or lists of simple types:

class A:
    attr: int = 3

def foo() -> List[A]:
    pass

def bar() -> Tuple[A, A]:
    pass

# example code
a = lib.foo()[0]
a.attr  # properly linked
b, c = lib.bar()  # b and c linked to A

I'm not sure what to do with other than constant integer subscripts though.

felix-hilden commented 2 years ago

The subscripts might also be slices, so we definitely need a way to recognise them or ignore cases that are too complex.