Fix pyrefly type error and modernize type hints in CohenKappa#3495
Fix pyrefly type error and modernize type hints in CohenKappa#3495
Conversation
Co-authored-by: vfdev-5 <[email protected]>
|
Great! Let's now also modernize the type hints : |
Co-authored-by: vfdev-5 <[email protected]>
Done in commit b897611. All type hints in the file have been modernized to use the |
|
@copilot type checking CI job reports : |
Co-authored-by: vfdev-5 <[email protected]>
... Fixed in commit cfc8930. Added explicit type annotation for self.weights: Literal["linear", "quadratic"] | None = weightsThe type checker was inferring |
Co-authored-by: vfdev-5 <[email protected]>
Fix pyrefly type error and modernize type hints in CohenKappa
weightsparameter fromOptional[str]toLiteral["linear", "quadratic"] | Nonedeviceparameter type annotation fromUnion[str, torch.device]tostr | torch.device|operator instead ofOptionalandUnion)OptionalandUnionfromtypingimportsself.weightsattribute to preserve Literal typeSummary
Fixed the pyrefly type checking error by:
weightsparameter type fromOptional[str]toLiteral["linear", "quadratic"] | Noneself.weightsto preserve the Literal type through assignment|syntaxThe type checker was inferring
self.weightsasstr | Noneinstead ofLiteral['linear', 'quadratic'] | Nonebecause Python doesn't automatically preserve Literal types through assignment. The explicit type annotation on line 72 ensures the type checker recognizes the correct type whenself.weightsis passed to sklearn'scohen_kappa_score.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.