Skip to content

Use --strict for selfcheck - #13464

Merged
JelleZijlstra merged 4 commits into
python:masterfrom
AlexWaygood:selfcheck
Aug 26, 2022
Merged

JelleZijlstra merged 4 commits into
python:masterfrom
AlexWaygood:selfcheck

Conversation

@AlexWaygood

Copy link
Copy Markdown
Member

The only check that wasn't already enabled was --warn-return-any.

@github-actions

This comment has been minimized.

Comment thread mypy/literals.py Outdated
Comment thread mypy/literals.py Outdated
Comment thread mypy/stubtest.py
def has_default(arg: Any) -> bool:
if isinstance(arg, inspect.Parameter):
return arg.default != inspect.Parameter.empty
return bool(arg.default != inspect.Parameter.empty)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am just curious: why != here does not return bool?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread mypy/types.py
def accept(self, visitor: TypeVisitor[T]) -> T:
assert isinstance(visitor, SyntheticTypeVisitor)
return visitor.visit_ellipsis_type(self)
return cast(T, visitor.visit_ellipsis_type(self))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you decide between cast and assert? 🤔

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would generally use assert wherever possible, as it provides runtime verification of the type narrowing. cast feels closer to telling the type checker to shut up and go away 😄

But here, we can't use assert — how can we assert that something is of type T, when we don't know what T is (since T is a TypeVar)? And this also feels like somewhere where, ideally, mypy should be able to infer that the returned type is of type T without any manual type narrowing. So in this specific situation, I'm more at ease with telling the type checker to shut up and go away 😉

Comment thread mypy/nodes.py
# Handle __class__ so that isinstance still works...
if attr == "__class__":
return object.__getattribute__(self, attr)
return object.__getattribute__(self, attr) # type: ignore[no-any-return]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__getattribute__ feels like it could be quite performance-sensitive, so type: ignore feels like the best option here imo.

@AlexWaygood
AlexWaygood requested a review from sobolevn August 21, 2022 10:33
@github-actions

This comment has been minimized.

@sobolevn sobolevn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

Let's wait for one more :)

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JelleZijlstra
JelleZijlstra merged commit 0406826 into python:master Aug 26, 2022
@AlexWaygood
AlexWaygood deleted the selfcheck branch August 26, 2022 06:09
@AlexWaygood

Copy link
Copy Markdown
Member Author

Thanks @sobolevn and @JelleZijlstra!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants