Assigning values to variable of same name in match case causes "Unused variable:" warning

72 Views Asked by At

I have the following Python code:

def func(str_param):
    match str_param:
        case some_class.some_str:
            my_var = dict_a
        case some_class.some_str2:
            my_var = dict_b
        case some_class.some_str3:
            my_var = dict_c
        case _:
            raise someError()

    out = some_other_func(my_var)

PyDev shows a warning "Unused variable: my_var" for the first two definitions of my_var and I can't figure out why. If it's of any help, the dict_x are of type dictionary, str_param and some_strx are of type string.

I have the same match case structure in different places too and I get no warnings there. I wouldn't expect any warnings in my case. I am programming in Squish IDE 7.1.0 using Python 3.10.

Actual code with warning

Update: I also initialized the variable before the match case as an empty dictionary, but it still showed the "unused variable" warning, even though I use it as a parameter in my following function some_other_func(my_var).

0

There are 0 best solutions below