pyutils / line_profiler

Line-by-line profiling for Python
Other
2.57k stars 118 forks source link

Fix AttributeError on certain methods #191

Closed Theelx closed 1 year ago

Theelx commented 1 year ago

Fixes #183, as evidenced by https://github.com/Theelx/sciris/actions/runs/3616146614. This has a negligible impact on performance because add_function is only called once per function, and try/excepts are zero-cost in CPython 3.11 anyway, iirc.

I would add a test for this, but it seems to be inconsistent as to how to get this error to appear. Sometimes the error showed up on GitHub Actions, but not locally, so I have no way to confirm precisely what code caused this.

codecov[bot] commented 1 year ago

Codecov Report

Merging #191 (d7f766a) into main (83e4332) will not change coverage. The diff coverage is n/a.

Additional details and impacted files [![Impacted file tree graph](https://codecov.io/gh/pyutils/line_profiler/pull/191/graphs/tree.svg?width=650&height=150&src=pr&token=xIK8nFU3K5&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)](https://codecov.io/gh/pyutils/line_profiler/pull/191?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) ```diff @@ Coverage Diff @@ ## main #191 +/- ## ======================================= Coverage 49.24% 49.24% ======================================= Files 4 4 Lines 266 266 Branches 39 39 ======================================= Hits 131 131 Misses 121 121 Partials 14 14 ``` ------ [Continue to review full report at Codecov](https://codecov.io/gh/pyutils/line_profiler/pull/191?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None). > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) > `Δ = absolute (impact)`, `ø = not affected`, `? = missing data` > Powered by [Codecov](https://codecov.io/gh/pyutils/line_profiler/pull/191?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None). Last update [83e4332...d7f766a](https://codecov.io/gh/pyutils/line_profiler/pull/191?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None).
Erotemic commented 1 year ago

Thank you @Theelx for taking time to fix this. Let me know when this PR is ready, and I'll merge.

It would be nice if we could add a test for this though. I don't quite understand what is difficult to reproduce here.

Theelx commented 1 year ago

@Erotemic This PR is ready. The parts that are difficult to reproduce are that I don't actually know how this happened, because I don't fully understand the internals of method objects, and that when one uses the profile function as opposed to the profile decorator, this problem doesn't appear (even though it should be the same code path for both).

Mogost commented 1 year ago

Can confirm that this PR fixes #183