Repository navigation
Report error for NewType used with an unimported type #3580
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -479,12 +479,13 @@ main:5: error: Constraint 2 becomes List[Any] due to an unfollowed import | |
|
|
||
| [case testDisallowImplicitAnyNewType] | ||
| # flags: --ignore-missing-imports --disallow-any=unimported | ||
| from typing import NewType | ||
| from typing import NewType, List | ||
| from missing import Unchecked | ||
|
|
||
| Baz = NewType('Baz', Unchecked) | ||
| [out] | ||
| main:5: error: Argument 2 to NewType(...) must be subclassable (got Any) | ||
| # this case is handled elsewhere: Baz = NewType('Baz', Unchecked) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would still include the test here. Tests shouldn't follow the implementation too closely -- they should tests features.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, yeah, that makes sense. I was just worried that if someone changes the wording, they have to change the tests in several places vs in one spot. But I guess it's not too much work. |
||
| Baz = NewType('Baz', List[Unchecked]) # E: Argument 2 to NewType(...) becomes List[Any] due to an unfollowed import | ||
|
|
||
| [builtins fixtures/list.pyi] | ||
|
|
||
| [case testDisallowImplicitAnyCallableAndTuple] | ||
| # flags: --ignore-missing-imports --disallow-any=unimported | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seeing this finally made me realize why I'm not fond of the way you're organizing your flags. It's easy to imagine having a typo somewhere, e.g.
if 'unimprted in self.options.disalloy_anyand the mistake would only be detected by careful unit testing. OTOH if the test in the code wasif self.options.disallow_any_unimprtedthe static checks would flag it right away. Note that this is independent from the way the command-line UI looks -- you could still have--disallow-any=unimportedbut it would have to set a Boolean attributedisallow_any_unimportedin the Options object.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I think it's a very good point.
I will implement this in a different PR.