Argument-Clinic / cpython

The Python programming language
https://www.python.org/
Other
1 stars 0 forks source link

Argument Clinic: Remove METHOD_INIT and METHOD_NEW function kinds #23

Open erlend-aasland opened 1 year ago

erlend-aasland commented 1 year ago
AlexWaygood commented 1 year ago

I think you should assign three attributes in __post_init__:

class Function:
    # <-- snip -->
    def __post_init__(self) -> None:
        # <-- snip -->
        self.init_method = self.name == "__init__"
        self.new_method = self.name == "__new__"
        self.new_or_init = self.init_method or self.new_method

Then you wouldn't have to have so many "magic strings" everywhere -- everywhere you're currently doing if f.name == "__init__", you can just do if f.init_method

erlend-aasland commented 1 year ago

I think you should assign three attributes in __post_init__:

class Function:
    # <-- snip -->
    def __post_init__(self) -> None:
        # <-- snip -->
        self.init_method = self.name == "__init__"
        self.new_method = self.name == "__new__"
        self.new_or_init = self.init_method or self.new_method

Then you wouldn't have to have so many "magic strings" everywhere -- everywhere you're currently doing if f.name == "__init__", you can just do if f.init_method

Yeah, that's neat. I thought of doing something like that; I'm not a fan of the name == "__init__" comparisons either.