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

Support python 3.10+ #281

Open
leonardostefan opened this issue May 26, 2023 · 17 comments
Open

Support python 3.10+ #281

leonardostefan opened this issue May 26, 2023 · 17 comments

Comments

@leonardostefan
Copy link

I'm using mutmut in my work projects with python 3.10 and its working except for a single project that we are using the "new" syntax of match-case (PEP 634). In this case, mutmut broke and return 100% of mutants killeds

There's any planning to add full suport for python 3.10?

@boxed
Copy link
Owner

boxed commented May 26, 2023

Blocked by davidhalter/parso#138

@gulliver-madrid
Copy link

While waiting for the full support of Python 3.10, is there any recommended workaround that could be used for projects employing the match-case syntax? Any tips would be greatly appreciated.

@boxed
Copy link
Owner

boxed commented Apr 16, 2024

Sorry, I don't really have anything to say to that. Extracting code you need to be mutation tested and testing it in a separate project is one way at least.. not great but 🤷

@nkhitrov
Copy link

Hello there! Any news?

@boxed
Copy link
Owner

boxed commented Jun 14, 2024

Read the linked issues for parso

@nkhitrov
Copy link

Last comment was 2 years ago. It looks like nobody cares about this problem. Maybe change the parser? For example, to libcst?

@boxed
Copy link
Owner

boxed commented Jun 14, 2024

Yea, that's one way to go for sure. I switched AST library for mutmut once before, and that wasn't as hard as one might expect. I'm very open to PRs, but I don't have much time for this myself.

@boxed
Copy link
Owner

boxed commented Jun 14, 2024

I've also thought about using whatever Ruff uses, or whatever black uses...

@yonkeltron
Copy link

FYI, there seems to be another issue which I've uncovered coming from parso. I'm not sure if it's the same or not, so please let me know if I should open up a new issue, instead.

This seems to be a parso problem with import asyncio:

$ mutmut run

- Mutation testing starting -

These are the steps:
1. A full test suite run will be made to make sure we
   can run the tests successfully and we know how long
   it takes (to detect infinite loops for example)
2. Mutants will be generated and checked

Results are stored in .mutmut-cache.
Print found mutants with `mutmut results`.

Legend for output:
🎉 Killed mutants.   The goal is for everything to end up in this bucket.
⏰ Timeout.          Test suite took 10 times as long as the baseline so were killed.
🤔 Suspicious.       Tests took a long time, but not long enough to be fatal.
🙁 Survived.         This means your tests need to be expanded.
🔇 Skipped.          Skipped.

mutmut cache is out of date, clearing it...
1. Running tests without mutations
⠸ Running...Done
Failed to parse app/cli/commands/relay_events/relay_handlers.py. Internal error from parso follows.
----------------------------------
Traceback (most recent call last):
  File "/virtualenvs/service-f1pOEzwg-py3.12/lib/python3.12/site-packages/parso/parser.py", line 180, in _add_token
    plan = stack[-1].dfa.transitions[transition]
           ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
KeyError: <PythonTokenTypes.NAME: TokenType(NAME)>

During handling of the above exception, another exception occurred:

SNIP

RuntimeError: Failed while creating mutations for app/cli/commands/relay_events/relay_handlers.py, for line "import asyncio"

Is this something new which needs a new issue or is this related to the same parso issue above?

@FrozenDude101
Copy link

FrozenDude101 commented Sep 1, 2024

I think this is related to parso, any python file using the "type" keyword added in 3.12 errors:
parso.parser.ParserSyntaxError: ('SyntaxError: invalid syntax', <ErrorLeaf: PythonTokenTypes.NAME:'Foo', (17, 5)>)
The above exception was the direct cause of the following exception:
RuntimeError: Failed while creating mutations for pyastodon/models\application.py, for line "from typing import Optional"

A minimal file is just:
type Foo = int

@jhovell
Copy link

jhovell commented Oct 13, 2024

... Extracting code you need to be mutation tested and testing it in a separate project is one way at least.. not great but 🤷

I'm surprised the workaround would have to be so painful / impractical. In particular I'm puzzled why excluding files with match or other newer keywords doesn't seem to work either excluding offending files via def pre_mutation(context): or via --paths-to-exclude ... based on adding some debug statements it seems like the error is hit before any files are excluded or pre_mutation is run. Would it be hard to make sure files are excluded before they are attempted to be parsed?

@boxed
Copy link
Owner

boxed commented Oct 13, 2024

As it stands right now I am in the process of writing version 3.0 of mutmut which is a big rewrite basically. After this is released, the AST library can be replaced (again).

I just have to guess and hope that any AST lib I choose to use will be kept up to date. This is the second time I've been burned by this specific problem.

@boxed boxed changed the title Suport to python 3.10 Support python 3.10+ Oct 20, 2024
@boxed
Copy link
Owner

boxed commented Oct 20, 2024

Mutmut 3 is released. I did not switch AST library, so maybe that's next on the agenda.

@jhovell
Copy link

jhovell commented Oct 20, 2024

nice! congrats. so just to be clear though that means if there are python 3.10+ keywords like match it’ll crash or is there any improvements in workarounds?

@boxed
Copy link
Owner

boxed commented Oct 20, 2024

Yea. It'll still crash on parsing that entire file. I guess it should be pretty simple to make mutmut just skip all files it can't parse.

@jhovell
Copy link

jhovell commented Oct 20, 2024

i would +1 that idea. would improve a major impediment to practical usage in an existing project

@boxed
Copy link
Owner

boxed commented Oct 20, 2024

3.0.2 released with this fix (and another tiny thing that was a showstopper too)

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

No branches or pull requests

7 participants