MCPcopy
hub / github.com/python/mypy / done

Method done

mypy/partially_defined.py:147–170  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

145 return False
146
147 def done(self) -> BranchState:
148 # First, compute all vars, including skipped branches. We include skipped branches
149 # because our goal is to capture all variables that semantic analyzer would
150 # consider defined.
151 all_vars = set()
152 for b in self.branches:
153 all_vars.update(b.may_be_defined)
154 all_vars.update(b.must_be_defined)
155 # For the rest of the things, we only care about branches that weren't skipped.
156 non_skipped_branches = [b for b in self.branches if not b.skipped]
157 if non_skipped_branches:
158 must_be_defined = non_skipped_branches[0].must_be_defined
159 for b in non_skipped_branches[1:]:
160 must_be_defined.intersection_update(b.must_be_defined)
161 else:
162 must_be_defined = set()
163 # Everything that wasn't defined in all branches but was defined
164 # in at least one branch should be in `may_be_defined`!
165 may_be_defined = all_vars.difference(must_be_defined)
166 return BranchState(
167 must_be_defined=must_be_defined,
168 may_be_defined=may_be_defined,
169 skipped=len(non_skipped_branches) == 0,
170 )
171
172
173class ScopeType(Enum):

Callers 1

end_branch_statementMethod · 0.80

Calls 4

setClass · 0.85
BranchStateClass · 0.85
lenFunction · 0.85
updateMethod · 0.45

Tested by

no test coverage detected