Skip to content

inspect.getsource (findsource) not working as expected when duplicate class is used #106727

Closed
@Viicos

Description

@Viicos

Bug report

Consider the following example:

import inspect class Model: a = 1 class Model: a = 2 print(Model.a) #> 2 print(inspect.getsource(Model)) #> class Model: #> a = 1

I think we should expect the last class to be used (it works as expected if we use functions instead of classes).

This issue was raised in an external project:

And I'm facing this issue while working on:

Let me know if this should be fixed, I'll take a deeper look at what was done in #10307 and see if I can make a PR

Your environment

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

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions