inspect_type_links.first.Foo | My Python Project

# inspect_type_links. first.Foo class

A class in the first module

first.Foo and inspect_type_links.first.Foo should lead to self; referencing the subclass via Foo, Foo.Foo, first.Foo.Foo or Bar. second.Foo and inspect_type_links.Bar lead to other classes.

This is consistent with how Python type annotations inside a class are interpreted -- see reference_self_data, reference_inner_data and reference_inner_other_data. Inside function definitions the rules are different as per https://docs.python.org/3/reference/executionmodel.html#resolution-of-names:

> The scope of names defined in a class block is limited to the class block; it does not extend to the code blocks of methods

This means relative annotations in reference_self(), reference_inner() and reference_inner_other() are parsed differently -- but in the documentation, these are shown with the same rules as for data themselves.

## Classes

class Bar
  Another inner class.
class Foo
  An inner class in the first module

## Methods

def reference_inner(self, a: Foo, b: Foo)
  Referencing an inner class using Foo.Foo and first.Foo.Foo. Outside of a function it would be enough to reference via Foo, thus docs display just Foo.
def reference_inner_other(self, a: Bar)
  Referencing another inner class using Foo.Bar. Bar alone doesn't work, outside of a function it would, thus docs display just Bar.
def reference_other(self, a: second.Foo, b: inspect_type_links.Bar)
  Referencing a type in another module using second.Foo or inspect_type_links.Bar.
def reference_parent(self, a: inspect_type_links.Foo)
  Referencing a class in a parent module using inspect_type_links.Foo.
def reference_self(self, a: first.Foo, b: first.Foo)
  Referencing its wrapper class using Foo and first.Foo. Outside of a function Foo would reference the inner, thus docs display first.Foo to disambiguate.

## Data

reference_inner_data: typing.Tuple[Foo, Foo, Foo] = {}
  Referencing the inner class using `Foo`, `Foo.Foo` or `first.Foo.Foo`, displayed as just `Foo`. This is different from reference_inner().
reference_inner_other_data: typing.Tuple[Bar, Bar, Bar] = {}
  Referencing another inner class using `Bar`, `Foo.Bar` or `first.Foo.Bar`, displayed as just `Bar`. This is different from reference_inner_other().
reference_self_data: typing.Tuple[first.Foo] = {}
  Referencing its wrapper class using `first.Foo`, displayed as `first.Foo` as well. `Foo` alone would reference the inner. This is different from reference_self().