yt-project / yt

Main yt repository
http://yt-project.org
Other
469 stars 280 forks source link

RFC: refactor geometry matching clauses with Python 3.10's pattern matching #5051

Closed neutrinoceros closed 1 week ago

neutrinoceros commented 1 week ago

PR Summary

Now that we don't support 3.9 anymore we have access to match/case statements (pattern matching). Arguably this improves readability in these instances, albeit at the cost of an additional indentation level.

neutrinoceros commented 1 week ago

is there something about the way the | is evaluated in the cases that means it has to be put in the case?

If you're asking if | has a syntactically different meaning in the context of case clauses, the answer is yes. See https://peps.python.org/pep-0636/#or-patterns

could we create top-level special cases like HAS_Z_AXIS for CARTESIAN | POLAR | SPECTRAL_CUBE ?

I think this would be achievable using IntFlag enums, however we need geometry to be an StrEnum for backward compatibility, and I don't fancy trying to implement a common subclass.

matthewturk commented 1 week ago

I think this would be achievable using IntFlag enums, however we need geometry to be an StrEnum for backward compatibility, and I don't fancy trying to implement a common subclass.

Me neither! I think the first answer, that | is syntactically different, is enough to say this is perfect as-is. Thank you!

neutrinoceros commented 1 week ago

I want to push couple times to this branch before I can undraft this.

neutrinoceros commented 1 week ago

I'll merge now to save myself some conflict solving later.