Skip to content

Class variable intialized with object: value rendered as None #30

@powderflask

Description

@powderflask

Great work! I'm converting a project from autodoc, and loving the improvements...
Came across this, its a bit of a show-stopper:

Code like this:

class Foo:
    """I'm a Foo"""
    pass

class Bar:
    """I'm composed of Foo"""

    s = "just fine"

    my_foo = Foo()
    """ What the foo?"""

    i = 42  # no problem

renders to:

.. py:class:: Bar
   :canonical: scratch.Bar

   .. autodoc2-docstring:: scratch.Bar

   .. py:attribute:: s
      :canonical: scratch.Bar.s
      :value: 'just fine'

      .. autodoc2-docstring:: scratch.Bar.s

   .. py:attribute:: my_foo
      :canonical: scratch.Bar.my_foo
      :value: None

      .. autodoc2-docstring:: scratch.Bar.my_foo

   .. py:attribute:: i
      :canonical: scratch.Bar.i
      :value: 42

Was expecting value of my_foo to be Foo().

I think this is a known issue in astroid_utils

def get_const_values(node: nodes.NodeNG) -> t.Any:
    """Get the value of a constant node."""
    # TODO its not ideal that this goes to None if not understood

Any work around for this?
thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions