Skip to content

New test and handling for maybe_compare_idx==None; fixes TypeError causing Pynguin to abort. #51

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

Merged
merged 2 commits into from
Jan 16, 2024

Conversation

jaltmayerpizzorno
Copy link
Contributor

The new test I include in this PR reproduces conditions that lead to maybe_compare_idx == None in _instrument_cond_jump (from instrumentation.py), causing the error

TypeError: list indices must be integers or slices, not NoneType

I just added handling to avoid the TypeError; Pynguin maintainers, please decide if this is the right thing to do, and provide any appropriate assertions in the new test.

This was tested with Python 3.10.12, as distributed by homebrew, on a MacOS system.

@stephanlukasczyk
Copy link
Member

Thank you for your PR! To get a better understanding of when this is actually happening and to allow me to reason about your changes and appropriate assertions, do you have a minimal Python module and Pynguin command line that triggers the exception you've mentioned?

@jaltmayerpizzorno
Copy link
Contributor Author

Thank you for your PR! To get a better understanding of when this is actually happening and to allow me to reason about your changes and appropriate assertions, do you have a minimal Python module and Pynguin command line that triggers the exception you've mentioned?

You're welcome! :) I was using the command below on https://github.com/astanin/python-tabulate :

PYNGUIN_DANGER_AWARE=1 python3.10 -m pynguin --project-path tabulate --output-path pynguin-out --module-name tabulate  -v

The function it aborted while instrumenting is _isint:

def _isint(string, inttype=int):
    """
    >>> _isint("123")
    True
    >>> _isint("123.45")
    False
    """
    return (
        type(string) is inttype
        or (
            (hasattr(string, "is_integer") or hasattr(string, "__array__"))
            and str(type(string)).startswith("<class 'numpy.int")
        )  # numpy.int64 and similar
        or (
            isinstance(string, (bytes, str)) and _isconvertible(inttype, string)
        )  # integer as string
    )

The new test in this PR is a somewhat minimized version of this function.

But I've come across the same problem while trying Pynguin on on other code as well. I didn't look deeper to see what exactly was causing it (but it seems that the Python compiler is generating bytecode that the instrumentation layer doesn't expect).

@stephanlukasczyk
Copy link
Member

Thank you for the details. I'll look into the proposed changes as soon as possible, but most likely not before next week.

@stephanlukasczyk stephanlukasczyk merged commit 7725c33 into se2p:main Jan 16, 2024
@stephanlukasczyk
Copy link
Member

I've merged this PR (extended by some assertions) in ed7c6a8

stephanlukasczyk added a commit that referenced this pull request Feb 22, 2024
- Fix `TypeError` bug in instrumentation of bytecode (closes GitHub PR
  #51)
- Add a dump method for type-information statistics
- Fix handling of aliased modules (fixes GitHub issue #57, merges #58)
- Fix method-signature handling for C extensions (fixed GitHub issue
  #59, merges #60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants