From 25f2f18dd17fa87e504be34bc1e7012588546e5a Mon Sep 17 00:00:00 2001 From: rechen Date: Thu, 9 Jul 2020 18:41:40 -0700 Subject: [PATCH] Hide some new behavior behind --check-attribute-types. These two changes generate more new findings than expected, so hide them behind a flag to clean up pytype head. PiperOrigin-RevId: 320523068 --- pytype/output.py | 3 ++- pytype/vm.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pytype/output.py b/pytype/output.py index 1cfcc8a65..96a3e0af6 100644 --- a/pytype/output.py +++ b/pytype/output.py @@ -582,7 +582,8 @@ def _class_to_def(self, node, v, class_name): # instance-level attributes for instance in set(v.instances): for name, member in instance.members.items(): - if name in CLASS_LEVEL_IGNORE or name in annotated_names: + if name in CLASS_LEVEL_IGNORE or ( + self.vm.options.check_attribute_types and name in annotated_names): continue for value in member.FilteredData(self.vm.exitpoint, strict=False): constants[name].add_type(value.to_type(node)) diff --git a/pytype/vm.py b/pytype/vm.py index 2721f61a0..4dc77b87d 100644 --- a/pytype/vm.py +++ b/pytype/vm.py @@ -2227,7 +2227,8 @@ def byte_STORE_ATTR(self, state, op): if not isinstance(maybe_cls, abstract.InterpreterClass): maybe_cls = maybe_cls.cls if isinstance(maybe_cls, abstract.InterpreterClass): - if ("__annotations__" not in maybe_cls.members and + if (self.options.check_attribute_types and + "__annotations__" not in maybe_cls.members and op.line in self.director.annotations): # The class has no annotated class attributes but does have an # annotated instance attribute.