Giter Site home page Giter Site logo

Comments (7)

sobolevn avatar sobolevn commented on August 17, 2024

Test itself: https://github.com/wemake-services/wemake-python-styleguide/blob/master/tests/test_checker/test_hypothesis.py#L39

from hypothesmith.

Zac-HD avatar Zac-HD commented on August 17, 2024

Huh. Can you reproduce this with the compile('globalA\\ \n#\n', '<string>', 'single') call? In my Python 3.9 env this just raises a SyntaxError: unexpected character after line continuation character, which is much less interesting.

If you can reproduce, we should report this upstream to CPython core.

from hypothesmith.

sobolevn avatar sobolevn commented on August 17, 2024

I am trying to reproduce this on 3.9.1 (originally happened on 3.9.8):


>   ???
E   hypothesis.errors.DidNotReproduce: The shape of the test data has changed in some way from where this blob was defined. Are you sure you're running the same test?

tests/test_checker/test_hypothesis.py:40: DidNotReproduce

Right now 3.9.8 is not available in pyenv: pyenv/pyenv#2152

from hypothesmith.

sobolevn avatar sobolevn commented on August 17, 2024

@Zac-HD I just got another one!

https://github.com/wemake-services/wemake-python-styleguide/runs/4175737661?check_suite_focus=true#step:7:1041

This one is different, it also has warnings:

 =================================== FAILURES ===================================
______________________________ test_no_exceptions ______________________________

self = <hypothesmith.syntactic.GrammarStrategy object at 0x7ffa6e39ab80>
data = ConjectureData(VALID, 26 bytes, frozen)
symbol = NonTerminal('simple_stmt')
draw_state = DrawState(result=['global', 'A', '\\ \n', ';', '\n'])

    def draw_symbol(self, data, symbol, draw_state):  # type: ignore
        count = len(draw_state.result)
        super().draw_symbol(data, symbol, draw_state)
        if symbol.name in COMPILE_MODES:
            try:
>               compile(
                    source="".join(draw_state.result[count:]),
                    filename="<string>",
                    mode=COMPILE_MODES[symbol.name],
                )
E               SystemError: Negative size passed to PyUnicode_New

.venv/lib/python3.9/site-packages/hypothesmith/syntactic.py:110: SystemError

The above exception was the direct cause of the following exception:

default_options = options(min_name_length=2, max_name_length=45, i_control_code=True, i_dont_control_code=True, max_noqa_comments=10, ne...gnitive_average=8, max_call_level=3, max_annotation_complexity=3, max_import_from_members=8, max_tuple_unpack_length=4)
parse_ast_tree = <function parse_ast_tree.<locals>.factory at 0x7ff8dfa10c10>
parse_tokens = <function parse_tokens.<locals>.factory at 0x7ff8df980160>

>   ???

tests/test_checker/test_hypothesis.py:40: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.venv/lib/python3.9/site-packages/hypothesmith/syntactic.py:89: in do_draw
    result = super().do_draw(data)
.venv/lib/python3.9/site-packages/hypothesis/extra/lark.py:153: in do_draw
    self.draw_symbol(data, start, state)
.venv/lib/python3.9/site-packages/hypothesmith/syntactic.py:107: in draw_symbol
    super().draw_symbol(data, symbol, draw_state)
.venv/lib/python3.9/site-packages/hypothesis/extra/lark.py:181: in draw_symbol
    self.draw_symbol(data, e, draw_state)
.venv/lib/python3.9/site-packages/hypothesmith/syntactic.py:107: in draw_symbol
    super().draw_symbol(data, symbol, draw_state)
.venv/lib/python3.9/site-packages/hypothesis/extra/lark.py:181: in draw_symbol
    self.draw_symbol(data, e, draw_state)
.venv/lib/python3.9/site-packages/hypothesmith/syntactic.py:107: in draw_symbol
    super().draw_symbol(data, symbol, draw_state)
.venv/lib/python3.9/site-packages/hypothesis/extra/lark.py:181: in draw_symbol
    self.draw_symbol(data, e, draw_state)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <hypothesmith.syntactic.GrammarStrategy object at 0x7ffa6e39ab80>
data = ConjectureData(VALID, 26 bytes, frozen)
symbol = NonTerminal('simple_stmt')
draw_state = DrawState(result=['global', 'A', '\\ \n', ';', '\n'])

    def draw_symbol(self, data, symbol, draw_state):  # type: ignore
        count = len(draw_state.result)
        super().draw_symbol(data, symbol, draw_state)
        if symbol.name in COMPILE_MODES:
            try:
                compile(
                    source="".join(draw_state.result[count:]),
                    filename="<string>",
                    mode=COMPILE_MODES[symbol.name],
                )
            except SyntaxError:
                # Python's grammar doesn't actually fully describe the behaviour of the
                # CPython parser and AST-post-processor, so we just filter out errors.
                assume(False)
            except Exception as err:  # pragma: no cover
                # Attempting to compile almost-valid strings has triggered a wide range
                # of bizzare errors in CPython, especially with the new PEG parser,
                # and so we maintain this extra clause to ensure that we get a decent
                # error message out of it.
                if isinstance(err, SystemError) and sys.version_info[:3] == (3, 9, 0):
                    # We've triggered https://bugs.python.org/issue42218 - it's been
                    # fixed upstream, so we'll treat it as if it were a SyntaxError.
                    assume(False)
                source_code = ascii("".join(draw_state.result[count:]))
>               raise type(err)(
                    f"compile({source_code}, '<string>', "
                    f"{COMPILE_MODES[symbol.name]!r}) "
                    f"raised {type(err).__name__}: {str(err)}"
                ) from err
E               SystemError: compile('globalA\\ \n;\n', '<string>', 'single') raised SystemError: Negative size passed to PyUnicode_New

.venv/lib/python3.9/site-packages/hypothesmith/syntactic.py:129: SystemError
---------------------------------- Hypothesis ----------------------------------
Highest target scores:
              19  (label='(hypothesmith) number of unique ast node types')
              46  (label='(hypothesmith) instructions in bytecode')
              74  (label='(hypothesmith) total number of ast nodes')


You can reproduce this example by temporarily adding @reproduce_failure('6.24.2', b'AXicY2RkYGJlYGQAAWZGCA0hAQFGABE=') as a decorator on your test case
=============================== warnings summary ===============================
tests/test_checker/test_hypothesis.py: 933 warnings
  <string>:1: SyntaxWarning: 'int' object is not callable; perhaps you missed a comma?

tests/test_checker/test_hypothesis.py: 916 warnings
  <string>:3: SyntaxWarning: 'int' object is not callable; perhaps you missed a comma?

-- Docs: https://docs.pytest.org/en/stable/warnings.html

----------- coverage: platform linux, python 3.9.8-final-0 -----------
Name    Stmts   Miss Branch BrPart  Cover   Missing
---------------------------------------------------
---------------------------------------------------
TOTAL    6290      0   2813      0   100%

141 files skipped due to complete coverage.
Coverage HTML written to dir htmlcov
Coverage XML written to file coverage.xml

Required test coverage of 100% reached. Total coverage: 100.00%
============================= SnapshotTest summary =============================
11 snapshots passed.
=========================== short test summary info ============================
FAILED tests/test_checker/test_hypothesis.py::test_no_exceptions - SystemErro...
==== 1 failed, 32026 passed, 12 skipped, 1849 warnings in 330.95s (0:05:30) ====
make: *** [Makefile:14: unit] Error 1

from hypothesmith.

Zac-HD avatar Zac-HD commented on August 17, 2024

The pyenv PR you linked to has been merged four days ago, so I think it should work?

This does seem like a real bug if we can trigger it with multiple inputs like this; I'd suggest one more attempt to reproduce and then reporting upstream with links to https://bugs.python.org/issue42218 https://bugs.python.org/issue40661 and https://bugs.python.org/issue42109

from hypothesmith.

Zac-HD avatar Zac-HD commented on August 17, 2024

Ah, https://bugs.python.org/issue45738 has already been opened.

from hypothesmith.

Zac-HD avatar Zac-HD commented on August 17, 2024

Fixed in 67fe545, version 0.2.0 released 🎉

from hypothesmith.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.