Detect circular references

Write codeMedium16 minStripe style

Your task

A feature-flag file is lines of the exact form "KEY=value" (split on the first "="). Values may mention other keys with the syntax "OTHER". Your linter must reject files where following such mentions can loop forever. Treat each mention of an EXISTING key as an edge from the defining key to the mentioned key; mentions of undefined names are harmless and ignored, as is any malformed "{" without a closing "}". Return true when the resulting graph contains a cycle (a key mentioning itself counts), false otherwise.

Examples

has_circular_reference(lines: list[str]) -> bool
Example 1
Inputhas_circular_reference(["A=${B}", "B=${A}"])
OutputTrue
Example 2
Inputhas_circular_reference(["A=${B}", "B=ok"])
OutputFalse