You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 8, 2021. It is now read-only.
The rules are very simple, but require a bunch of redundant checks. More importantly, we can't introspect them to determine if one rule is shadowing another.
While writing up the standard rules, I've observed several patterns:
type == X all the atom types
issubclass(type, X) enums must use issubclass; atoms presently use this as well.
type.__origin__ == X the generic types.
issubclass(type.__origin__, X) the subclass variant is not used.
hasattr(type, X) - used to match attrs and dataclass
type.__args__ =~ [X, NoneType] used to match Optional as it's a special case of Union.
The concrete and generic types are not entirely exclusive because user classes can subclass some generic types. (You can subclass something like typing.List[foo], but not typing.Union.)
If we simply had a mapping of known atom types, it's easy enough to look them up. And if you specify two atom types, this should raise an error as one is entirely shadowing another.
An issubclass test can walk .mro() until a base is a match in the mapping.
Each pattern represents a phase, and each phase has a "least-order." If a match is found that is greater than another phase's least-order, that phase can be disregarded and the search is complete.
Making type matches work with subclass matches mean we want is-proper-subclass-of rather than issuclass's improper semantics so there's no overlap.
The text was updated successfully, but these errors were encountered:
The rules are very simple, but require a bunch of redundant checks. More importantly, we can't introspect them to determine if one rule is shadowing another.
While writing up the standard rules, I've observed several patterns:
type == X
all the atom typesissubclass(type, X)
enums must useissubclass
; atoms presently use this as well.type.__origin__ == X
the generic types.issubclass(type.__origin__, X)
the subclass variant is not used.hasattr(type, X)
- used to matchattrs
anddataclass
type.__args__ =~ [X, NoneType]
used to matchOptional
as it's a special case ofUnion
.The concrete and generic types are not entirely exclusive because user classes can subclass some generic types. (You can subclass something like
typing.List[foo]
, but nottyping.Union
.)If we simply had a mapping of known atom types, it's easy enough to look them up. And if you specify two atom types, this should raise an error as one is entirely shadowing another.
An
issubclass
test can walk.mro()
until a base is a match in the mapping.Each pattern represents a phase, and each phase has a "least-order." If a match is found that is greater than another phase's least-order, that phase can be disregarded and the search is complete.
Making type matches work with subclass matches mean we want
is-proper-subclass-of
rather thanissuclass
's improper semantics so there's no overlap.The text was updated successfully, but these errors were encountered: