A string holding a valid object name in this version of Python. This does not check that the name exists in any scope.
| 3031 | |
| 3032 | |
| 3033 | class ObjectName(TraitType[str, str]): |
| 3034 | """A string holding a valid object name in this version of Python. |
| 3035 | |
| 3036 | This does not check that the name exists in any scope.""" |
| 3037 | |
| 3038 | info_text = "a valid object identifier in Python" |
| 3039 | |
| 3040 | coerce_str = staticmethod(lambda _, s: s) |
| 3041 | |
| 3042 | def validate(self, obj: t.Any, value: t.Any) -> str: |
| 3043 | value = self.coerce_str(obj, value) |
| 3044 | |
| 3045 | if isinstance(value, str) and value.isidentifier(): |
| 3046 | return value |
| 3047 | self.error(obj, value) |
| 3048 | |
| 3049 | def from_string(self, s: str) -> str | None: |
| 3050 | if self.allow_none and s == "None": |
| 3051 | return None |
| 3052 | return s |
| 3053 | |
| 3054 | |
| 3055 | class DottedObjectName(ObjectName): |
no outgoing calls
no test coverage detected
searching dependent graphs…