Remove optionality from name on all reasonable constructs. #77
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Despite virtually all constructs having a name,
name
was still marked asOptional[str]
everywhere. This PR narrows that tostr
wherever possible, so I don't have to do lots of None-checking or casting when grabbing the names of things. Some particular details:gave an unnamed OperationRest the empty string as a name, so it doesn't need to be Optional.
All the uses of OperationRest that can be unnamed just test if they're unnamed and substitute a more specific string, like
'__stringifier__'
; unfortunately methods, which are always named, don't have a more specific grammar construction, and so they get inconveniently lumped into here. The "am I unnamed" test just checks the name as a boolean, so empty string works great here.Similarly gave ExtendedAttributeUnknown an empty string as a name; it's a funky corner case that would otherwise infect ExtendedAttribute with an optional name even tho every recognized form of ExtendedAttribute has a name, and to avoid that you'd need to either always guard or always typecheck with one of the more specific subtypes, neither of which are useful to make authors do.
Could replace with a
raise
or something, tho, if desired.Similarly, gave it an empty string
normal_name
, thonormal_name
is often optional on other constructs. (Might be fixable, just didn't dive into it.)(Also added an
ExtendedAttributeType
alias that's a union of the specific subtypes, soExtendedAttribute
can properly narrow itsattribute
property and thus get good type-checking whenever it references that property.)Left the big general superclasses (
Construct
,Production
,ComplexProduction
) as having an optional name, as they don't have names and you really can't depend on things. Had to sprinkle a few casts around for things that can contain anything, likeNamespaceMember
orInterfaceMember
.Deleted ArgumentList's
name
attribute; it was very odd in the first place (returning the name of its first arg when it had exactly 1 arg, but None if it had 0 or 2+ args).Explored fixing
type_name
(/s
) as well (bunches of type-related classes that are eitherNone
despite having a reasonable type name or missing entirely), but I'm honestly not sure what it's meant to be used for in the first place - it doesn't look anything internal calls these. So I left them alone.