Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inspect.getmembers will call the instance __bases__ attribute, which may cause an exception #90261

Closed
hongweipeng mannequin opened this issue Dec 16, 2021 · 4 comments
Closed
Labels
3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@hongweipeng
Copy link
Mannequin

hongweipeng mannequin commented Dec 16, 2021

BPO 46103
Nosy @terryjreedy, @pitrou, @ethanfurman, @1st1, @hongweipeng
PRs
  • bpo-46103: Fix inspect.getmembers call the instance __bases__ attribute which ma… #30147
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2021-12-16.15:40:43.879>
    labels = ['type-bug', 'library', '3.11']
    title = 'inspect.getmembers will call the instance __bases__ attribute, which may cause an exception'
    updated_at = <Date 2022-01-23.17:40:42.489>
    user = 'https://github.com/hongweipeng'

    bugs.python.org fields:

    activity = <Date 2022-01-23.17:40:42.489>
    actor = 'ethan.furman'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2021-12-16.15:40:43.879>
    creator = 'hongweipeng'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46103
    keywords = ['patch']
    message_count = 3.0
    messages = ['408717', '408827', '411389']
    nosy_count = 6.0
    nosy_names = ['ping', 'terry.reedy', 'pitrou', 'ethan.furman', 'yselivanov', 'hongweipeng']
    pr_nums = ['30147']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue46103'
    versions = ['Python 3.11']

    @hongweipeng
    Copy link
    Mannequin Author

    hongweipeng mannequin commented Dec 16, 2021

    root@debian:/workspace/cpython# ./python
    Python 3.11.0a3+ (heads/main-dirty:b123ad8030, Dec 16 2021, 06:16:15) [GCC 10.2.1 20210110] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import inspect
    >>> class Foo:
    ...   def __getattr__(self, attr):
    ...     return None
    ... 
    >>> inspect.getmembers(Foo())
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/workspace/cpython/Lib/inspect.py", line 488, in getmembers
        return _getmembers(object, predicate, getattr)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/workspace/cpython/Lib/inspect.py", line 455, in _getmembers
        for base in object.__bases__:
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    TypeError: 'NoneType' object is not iterable

    @hongweipeng hongweipeng mannequin added 3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Dec 16, 2021
    @terryjreedy
    Copy link
    Member

    PR edits inspect._getmembers. I nosied people who have edited it previously.

    @ethanfurman
    Copy link
    Member

    New changeset 691506f by Weipeng Hong in branch 'main':
    bpo-46103: Fix inspect.getmembers to only get __bases__ from class (GH-30147)
    691506f

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @erlend-aasland
    Copy link
    Contributor

    Fixed with gh-30147.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants