Fix name mangling and typevar errors#895
Conversation
Inside the BaseDataProcessor class definition, references to __subclasses are automatically replaced with _BaseDataProcessor__subclasses. This remains the case even in static methods _register_subclass() and get_class(). Same with BaseModel and its __subclasses field. So we do not have to write out the full name mangled identifiers inside the class definitions. Also, mypy doesn't seem to be able to handle the return type of BaseDataProcessor.get_class() being a typevar, so that was changed to type[BaseDataProcessor]. This does not affect the functionality of get_class() since it always returns a subclass of BaseDataProcessor.
IIRC, there's actually intent to use |
@JGSweets Good point, I hadn't thought the case where Fortunately, it seems that since
|
I wonder if that is a change in py version. Maybe 3.6 or 3.7 didn't allow this, but we no longer support it anyways. |
| def get_class(cls: type[Processor], class_name: str) -> type[Processor] | None: | ||
| def get_class( | ||
| cls: type[BaseDataProcessor], class_name: str | ||
| ) -> type[BaseDataProcessor] | None: |
There was a problem hiding this comment.
Yup, makes sense that it isn't type[Processor]. While generics make sense at the top of the class, this output isn't related to the cls, but to the str.
|
@taylorfturner do we update for this to go into |
Definitely |
|
Because we are changing the base to |
I'm re-making my PRs based on |


Issue: #722
Inside the
BaseDataProcessorclass definition, all references to__subclassesare automatically replaced with_BaseDataProcessor__subclasses. This remains the case even in static methods_register_subclass()andget_class(). Same withBaseModeland its__subclassesfield. So we do not have to write out the full name mangled identifiers inside the class definitions.Also, mypy doesn't seem to be able to handle the return type of
BaseDataProcessor.get_class()being a typevar, so that was changed totype[BaseDataProcessor]. This does not affect the functionality ofget_class()since it always returns a subclass ofBaseDataProcessor.