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

Add `--allow-untyped-globals` flag that avoids partial type errors #5670

Merged
merged 7 commits into from Sep 26, 2018

Conversation

Projects
None yet
4 participants
@msullivan
Copy link
Collaborator

commented Sep 25, 2018

A major cause of false positives when checking new codebases is
unannotated top level containers and Nones.

Add a flag that suppresses both the "needs type annotation" errors and
the assigning of NoneTyp to variables at the "toplevel" (not when
nested in functions). To avoid throwing away too much type
information, we give more precise types in these situations than
previously, filling in the arguments to the type with Any.

Closes #5639.

I don't love the flag name and would be happy to change it. This just adds an individual flag. Grouping into a --strictness=0 configuration or something we should spin off as another bug, I think.

@msullivan msullivan requested review from JukkaL, gvanrossum and ilevkivskyi Sep 25, 2018

msullivan added some commits Sep 25, 2018

Add a `--permissive-toplevel` flag that avoids partial type errors
A major cause of false positives when checking new codebases is
unannotated top level containers and Nones.

Add a flag that suppresses both the "needs type annotation" errors and
the assigning of NoneTyp to variables at the "toplevel" (not when
nested in functions). To avoid throwing away too much type
information, we give more precise types in these situations than
previously, filling in the arguments to the type with `Any`.

Closes #5639.

@msullivan msullivan force-pushed the lenient-toplevel branch from 7c23ac4 to c352f83 Sep 25, 2018

Show resolved Hide resolved mypy/main.py Outdated
Show resolved Hide resolved mypy/main.py Outdated
Show resolved Hide resolved mypy/main.py Outdated
Show resolved Hide resolved test-data/unit/check-inference.test
reveal_type(x) # E: Revealed type is 'builtins.list[Any]'
reveal_type(y) # E: Revealed type is 'builtins.dict[Any, Any]'

[builtins fixtures/dict.pyi]

This comment has been minimized.

Copy link
@gvanrossum

gvanrossum Sep 25, 2018

Member

I'm curious why this doesn't pass:

class C:
    a = []  # Error here
    def f(self) -> None:
        reveal_type(self.a)

This still gives an error "Need type annotation for 'a'" on line 2.

This comment has been minimized.

Copy link
@msullivan

msullivan Sep 26, 2018

Author Collaborator

Because member checking has a totally different partial type path apparently, which I'm now going to merge.

@Michael0x2a

This comment has been minimized.

Copy link
Collaborator

commented Sep 25, 2018

Just a few thoughts about how we're categorizing this flag:

  1. We should add this flag to the config file docs somewhere -- probably as a per-module option?
  2. One idea is maybe to group this under the "untyped definitions and calls" section and name the flag something like --allow-untyped-globals. (I'm also not happy with this name, but starting the flag with words like "allow/disallow" feels a little more consistent with what the other flags are doing.)
@msullivan

This comment has been minimized.

Copy link
Collaborator Author

commented Sep 25, 2018

Re categorization:
The strictness group currently includes only the meta-option --strict, which doesn't seem like the right place for this.
"Untyped definitions and calls" is the closest fit, and I nearly lumped it in there, but it seemed like something of an outlier still. I'd be happy to move it back in there.

@gvanrossum

This comment has been minimized.

Copy link
Member

commented Sep 26, 2018

I still think it belongs better in strictness_group. This looks as follows currently:

Other strictness checks:
  --strict                  Strict mode; enables the following flags: --warn-
                            unused-configs, --disallow-subclassing-any,
                            --disallow-untyped-calls, --disallow-untyped-defs,
                            --disallow-incomplete-defs, --check-untyped-defs,
                            --disallow-untyped-decorators, --no-implicit-
                            optional, --warn-redundant-casts, --warn-unused-
                            ignores, --warn-return-any
@gvanrossum
Copy link
Member

left a comment

Yay!

@msullivan msullivan merged commit 87e3c71 into master Sep 26, 2018

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@msullivan msullivan deleted the lenient-toplevel branch Sep 26, 2018

@gvanrossum gvanrossum changed the title Add a `--permissive-toplevel` flag that avoids partial type errors Add `--allow-untyped-globals` flag that avoids partial type errors Oct 12, 2018

@gvanrossum

This comment has been minimized.

Copy link
Member

commented Oct 12, 2018

(Note that the flag ended up being renamed to --allow-untyped-globals, but the commit message wasn't adjusted. :-( )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.