Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upPrevent unions with itself #1997
Conversation
This reverts commit 6109ac7.
| @@ -28,15 +28,19 @@ internal sealed class PythonUnionType : LocatedMember, IPythonUnionType { | |||
|
|
|||
| public PythonUnionType(IEnumerable<IPythonType> types, IPythonModule declaringModule) | |||
| : base(declaringModule.Interpreter.ModuleResolution.GetSpecializedModule("typing")) { | |||
| _types.UnionWith(types); | |||
| _types.UnionWith(types.Where(t => !this.Equals(t))); | |||
jakebailey
Apr 17, 2020
Member
Do either of the constructors end up mattering? Or is it just Add that was the problem? I'm not sure how you could end up ever having an object "equal" to the current one if you're in the constructor for this, but I could be wrong.
MikhailArkhipov
Apr 17, 2020
Author
Member
It basically gets confused on
def get_if_str(self, obj: Union[str, Factory]):
"""
Returns object from the registry if ``obj`` type is string.
"""
if type(obj) is str:
return self.get(obj)
return objwhen calculating return value. Another option is to introduce deep compare to Union so !currentType.Equals(valueType) would trigger. But it would be narrower fix as there may be other calls to Add ending up with circular unions.
if (!_fromAnnotation && !currentType.Equals(valueType)) {
var type = PythonUnionType.Combine(currentType, valueType);
// Track instance vs type info.
StaticReturnValue = value is IPythonInstance ? type.CreateInstance(ArgumentSet.WithoutContext) : (IMember)type;
}
52a2397
into
microsoft:master
* Remove stale reference * Don't suppress LHS diagnostics on augmented assign * Revert "Don't suppress LHS diagnostics on augmented assign" This reverts commit 6109ac7. * Escape [ and ] * PR feedback * Prevent unions with itself * Add special Union comparison + test (cherry picked from commit 52a2397)
* Remove stale reference * Don't suppress LHS diagnostics on augmented assign * Revert "Don't suppress LHS diagnostics on augmented assign" This reverts commit 6109ac7. * Escape [ and ] * PR feedback * Prevent unions with itself * Add special Union comparison + test (cherry picked from commit 52a2397)
Fixes #1985