Skip to content

MAINT: Remove hasattr/getattr anti-patterns by initializing attributes to None #9880

Open

Description

@Aniketsy

The biggest challenge with statsmodels is there are too many attributes that are totally missing when not used. These should all be replaced with code like self.attr = None and then if something: self.attr = value. Statsmodels has a lot of code that uses hasattr and getattr(...,... default). Both of these are anti pattern imo.

originally suggested by @bashtage in #8679

I'm planning to work on this, so created a separate issue.

Actually, i was looking for the discussion of adding type hints in statsmodels, but haven't got clear decision in issue as i think there are some difficulties. I'd be happy to discuss if there are plans to add. Thanks!

Activity

  1. bashtage commented on Jul 1, 2026

    @bashtage
    Member
  2. added theissue type on Aug 11, 2026
  3. Mustaphayinka commented on Aug 23, 2026

    @Mustaphayinka

    Happy to help chip away at this. I see #10024 is handling the OLS attributes with the _NoValue sentinel pattern, is there a specific module or set of classes still unclaimed that I could take on using the same approach? Also happy to defer to @Aniketsy if you're already covering this broadly

  4. bashtage commented on Aug 23, 2026

    @bashtage
    Member

    Going to wait until after 0.15 is out, which should be later this month.

  5. Aniketsy commented on Aug 23, 2026

    @Aniketsy
    ContributorAuthor

    Happy to help chip away at this. I see #10024 is handling the OLS attributes with the _NoValue sentinel pattern, is there a specific module or set of classes still unclaimed that I could take on using the same approach? Also happy to defer to @Aniketsy if you're already covering this broadly

    Actually i did some work on this, back then when opened an issue, but stuck somewhere, so i'm planning to give this fresh start soon.

    Going to wait until after 0.15 is out, which should be later this month.

    oh that's good news, i guess there are soo many things fixed and improved in this release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions