coady / multimethod

Multiple argument dispatching.
https://coady.github.io/multimethod
Other
277 stars 24 forks source link

Fix creating unnecessary instances #80

Closed MordorianGuy closed 1 year ago

MordorianGuy commented 1 year ago

If a namespace already has a multimethod object, there is no need to create an unused instance with container attributes just to feed the garbage collector.

codecov[bot] commented 1 year ago

Codecov Report

Base: 100.00% // Head: 100.00% // No change to project coverage :thumbsup:

Coverage data is based on head (84c6ba5) compared to base (f29c975). Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #80 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 1 1 Lines 288 289 +1 Branches 75 76 +1 ========================================= + Hits 288 289 +1 ``` | [Impacted Files](https://codecov.io/gh/coady/multimethod/pull/80?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=A.+Coady) | Coverage Δ | | |---|---|---| | [multimethod/\_\_init\_\_.py](https://codecov.io/gh/coady/multimethod/pull/80?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=A.+Coady#diff-bXVsdGltZXRob2QvX19pbml0X18ucHk=) | `100.00% <100.00%> (ø)` | | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=A.+Coady). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=A.+Coady)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

MordorianGuy commented 1 year ago

It is a tiny optimisation. Since previously __new__ created a new instance with set & list attributes at any time but did not use it if the appropriate multimethod object had already existed in the namespace.

I was just feeding my curiosity about how the package works and noticed this.