Google sync#600
Merged
Merged
Conversation
…notation. With this change, pytype will report an error for: x: str = 0 by default. Erroring on: x = 0 # type: str or x: str x = 0 will still require the --check-variable-types flag. PiperOrigin-RevId: 314234094
If options.check_variable_types is set, the following code should fail:
a: List[int] = []
a.append("hello")
Also adds some test cases in bugs/mutation.py for TODOs.
PiperOrigin-RevId: 314239043
…den. Exceptions (treated as ambiguous) are: - booleans - numeric types - classes overriding __bool__ (__nonzero__ in python2) - classes overriding __len__ Provably empty builtin containers continue to be treated as False. PiperOrigin-RevId: 314390311
New output format example:
File "third_party/py/pytype/bugs/mutation.py", line 19, in <module>: New container type does not match type annotation [container-type-mismatch]
Annotation: Dict[str, str] (type parameters Dict[_K, _V])
Contained types:
_K: str
_V: str
New contained types:
_K: Union[int, str]
_V: Union[float, str]
PiperOrigin-RevId: 314422487
Adds a new option, --check-attribute-types, that will make pytype type-check
attribute assignments against annotations, e.g.,
class Foo:
x: int
def foo(self):
self.x = 'hello, world' # annotation-type-mismatch
I've left a couple of features for future CLs:
* Making annotations take precedence over instance attribute values when
generating pyi files.
* Handling attribute type comments in __new__ and __init__.
Also puts container mutation checking behind its own flag,
--check-container-types, rather than reusing --check-variable-types. Having
this many flags is rather ugly and redundant, but they'll go away as we release
various things, and they make the release process a bit easier.
PiperOrigin-RevId: 314483072
A corner case where an alias can point to two separate annotated args via different code paths has been left as a TODO PiperOrigin-RevId: 314763912
Used in error messages when reporting container type annotation mismatches. PiperOrigin-RevId: 314791344
Showed up when attempting to analyze //apps/intelligence/cody/tools/codylab:testit. PiperOrigin-RevId: 314814112
PiperOrigin-RevId: 315326106
…biguous. Allows for the fact that __new__ might be called from a subclass of Foo, and that checking that we are not in the base class is a common idiom. PiperOrigin-RevId: 315538618
…aph. PiperOrigin-RevId: 315564137
import is a keyword and therefore is not a valid module name in Python. PiperOrigin-RevId: 315965683
PiperOrigin-RevId: 315968839
Prior to this change _get_match_location produced false-positive match when the name being matched occurred as a prefix of some other imported name, e.g. import foo as f PiperOrigin-RevId: 316128150
PiperOrigin-RevId: 316139475
With this change, v: int = 0 v = '' will also be an error. I already cleaned up all new findings introduced by this change as of about a week ago. PiperOrigin-RevId: 316170169
For python/typeshed#4224. We really need a better pyi parser... PiperOrigin-RevId: 316171517
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.