Skip to content

Unhandled StopIteration during node inference #1080

@jacobtylerwalls

Description

@jacobtylerwalls

Steps to reproduce

a.py

from b import getSourceFilePath

class A:
    languageCodes = ['en', 'fr', 'it', 'de', 'cn', 'nl']
    def readExcerpts(self):
        for languageCode in self.languageCodes:
            # does not need to be an existing path
            thisExcerpt = getSourceFilePath() / (languageCode + '.txt')
            with thisExcerpt.open(encoding='utf-8') as f:
                pass

b.py

import inspect
import pathlib

def getSourceFilePath() -> pathlib.Path:
    fpThis = pathlib.Path(inspect.getfile(getSourceFilePath)).resolve()
    return fpThis.parent.parent

Current behavior

Exception on node <AssignName.f l.9 at 0x7fd0582e4f10> in file ...
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/astroid/protocols.py", line 463, in _infer_context_manager
    inferred = next(mgr.infer(context=context))
StopIteration

python -c "from astroid import __pkginfo__; print(__pkginfo__.version)" output

2.6.1

Appears to be a regression in cf6528c.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions