Skip to content

option no-implicit-optional ignored as inline configuration and per-module flags #8029

Closed

Description

@fnep

I found a potential bug (not sure) with mypy 0.740 and Python 3.6.5 & Python 3.7.1.

The following code:

# mypy: no-implicit-optional

def add(self, a: int, b: int = None) -> int:
    return a + b

… gives me

run.py:4: error: Unsupported operand types for + ("int" and "None")
run.py:4: note: Right operand is of type "Optional[int]"

… but I would expect to get the more clear

run.py:3: error: Incompatible default for argument "b" (default has type "None", argument has type "int")

… because the inline config "no-implicit-optional" is set. It is the same if I have a per file/moule section in my mypy.ini, but it works i if define it globally (in [mypy] section) or via command line switch.

Activity

  1. ilevkivskyi commented on Nov 28, 2019

    @ilevkivskyi
    Member

    Hm, interesting. It seems to me this may be related to #7773. In particular, it seems to me logic of definition of --no-implicit-optional in mypy/main.py should match that of --no-warn-no-return.

    Also this is one of only two flags that have no_ prefix in mypy/options.py and both suffer from #7773.

  2. MrRaval17 commented on Mar 11, 2020

    @MrRaval17

    @ilevkivskyi I was able to reproduce the scenario mentioned by @efenka :
    image

    I also saw #7773 issue. I guess the "unrecognized options" error is being produced because the options which cause those errors are not defined in mypy/options.py or are defined with different names ?

    However I don't understand what you meant by this:

    In particular, it seems to me logic of definition of --no-implicit-optional in mypy/main.py should match that of --no-warn-no-return

    Did you mean to change line 548 in mypy/main.py:
    add_invertible_flag('--no-implicit-optional', default=False, strict_flag=True, help="Don't assume arguments with default values of None are Optional", group=none_group)

    to match line 570 in mypy/main.py:

    add_invertible_flag('--no-warn-no-return', dest='warn_no_return', default=True, help="Do not warn about functions that end without returning", group=lint_group)

  3. davidzwa commented on Mar 17, 2020

    @davidzwa
    Contributor

    @ilevkivskyi I saw your comment on no_* settings. I'm involved in the --no-site-packages issue #7768 (PR: #8524) and to do that I've added no_site_packages to options.py. I suspect if your intuition comes out to be true, my contribution there might influence it.

    I will look into this issue further Wednesday, so any other information might come in handy.

  4. srbhss commented on Mar 29, 2021

    @srbhss

    Hey @ilevkivskyi, I would like to work on this issue. Please assign me this one.

  5. ilevkivskyi commented on Mar 29, 2021

    @ilevkivskyi
    Member

    @srbhss OK, note however I may not have time to review your PR, but others might have.

  6. odesenfans commented on Jul 16, 2022

    @odesenfans

    This issue appears to be fixed in mypy 0.961.

  7. hauntsaninja commented on Jan 1, 2023

    @hauntsaninja
    Collaborator

    Looks like it got fixed a long time ago, somewhere between 0.780 and 0.790

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions