Skip to content

inspect.getattr_static vs getattr returns different result #100418

Closed as not planned
@yanboliang

Description

@yanboliang

Bug report

Repro:

class MyClass(object):
    def __init__(self, x):
        self.x = x

    def add(self, y):
        return self.x + y

a = MyClass(2)

print(inspect.getattr_static(a, "add"))
print(getattr(a, "add"))

Result:

<function MyClass.add at 0x7fec4ebe9310>
<bound method MyClass.add of <__main__.MyClass object at 0x7fec4fca3490>>

I'm not sure if this is a bug, but I'd like to understand the reason behind the difference. Since function and bound method are different type in Python, I think it should be a bound method in my case, but why inspect.getattr_static return function type?

Your environment

  • CPython versions tested on:
  • Operating system and architecture:

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions