mutmut icon indicating copy to clipboard operation
mutmut copied to clipboard

Issue with Context annotations

Open henryh9n opened this issue 3 years ago • 5 comments

Since the Context class is in the same file as the code that imports the mutmut_config, it cannot be used for the annotations. We are extensively using annotations in our code and want to do the same for mutmut_config.py. The issue is probably caused by cyclic import error and is shout since the import exceptions are in try-except.

I suggest moving the class into a separate module. In general, I think it's a good idea to separate the code into a few modules.

henryh9n avatar Oct 15 '20 13:10 henryh9n

Can't you handle this already with https://mypy.readthedocs.io/en/stable/common_issues.html#import-cycles ?

boxed avatar Oct 16 '20 07:10 boxed

Can't you handle this already with https://mypy.readthedocs.io/en/stable/common_issues.html#import-cycles ?

@boxed Technically we can, but since we are using the other (conventional) way of annotating our methods, it would have been nice to have a way to do it, but not use a tweak.

As some say,

Simple is better than complex.

henryh9n avatar Oct 16 '20 09:10 henryh9n

I can make a PR if you'll be able to merge and make a release.

henryh9n avatar Oct 16 '20 09:10 henryh9n

Hm.. well, I don't think moving the class to another module will help much, as you'd still trigger the import in __init__.py to get to a submodule right?

You'd have to make PR that changes the code so that the mutmut_config isn't imported automatically like that. This seems like a good change anyway since this is more of a hack than a good design imo. Maybe something like a function in mutmut/__init__.py called read_config that does looks something like this:

def read_config():
    try:
        import mutmut_config as mc
        global mutmut_config
        mutmut_config = mc
    except ImportError:
        pass

and then make sure that it's called by main().

boxed avatar Oct 16 '20 11:10 boxed

Hm.. well, I don't think moving the class to another module will help much, as you'd still trigger the import in __init__.py to get to a submodule right?

You'd have to make PR that changes the code so that the mutmut_config isn't imported automatically like that. This seems like a good change anyway since this is more of a hack than a good design imo. Maybe something like a function in mutmut/__init__.py called read_config that does looks something like this:

def read_config():
    try:
        import mutmut_config as mc
        global mutmut_config
        mutmut_config = mc
    except ImportError:
        pass

and then make sure that it's called by main().

Let me think a bit over this later today, I'll propose smt in a PR

henryh9n avatar Oct 16 '20 11:10 henryh9n