Skip to content

FIX: classmethods and staticmethods in profiler#59

Merged
ZLLentz merged 3 commits into
pcdshub:masterfrom
ZLLentz:fix-profiler-static-cls
Jun 17, 2022
Merged

FIX: classmethods and staticmethods in profiler#59
ZLLentz merged 3 commits into
pcdshub:masterfrom
ZLLentz:fix-profiler-static-cls

Conversation

@ZLLentz
Copy link
Copy Markdown
Member

@ZLLentz ZLLentz commented Jun 16, 2022

Description

Adjust the profile discovery mechanism so that it no longer skips classmethods and staticmethods. Both changes (getmembers, ismember) are needed.

Replicate the typhos PR mostly (pcdshub/typhos#505), adding tests

Motivation and Context

closes #57
closes #58

How Has This Been Tested?

Added tests, confirmed interactively that this reveals the pcdsdevices methods I was trying to see

Where Has This Been Documented?

Later in the release notes

@ZLLentz ZLLentz marked this pull request as ready for review June 16, 2022 23:17
@ZLLentz ZLLentz requested review from klauer and tangkong June 16, 2022 23:18
Copy link
Copy Markdown
Contributor

@klauer klauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing looks solid - I really like the approach you took, going so far as to check that individual functions get profiled. 👍

Comment thread pcdsutils/profile.py
output_now: bool = True,
min_threshold: float = 0,
) -> LineProfiler:
) -> Iterator[LineProfiler]:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha every time I do this there's some more precise way to hint things, I'll look at this again

Copy link
Copy Markdown
Member Author

@ZLLentz ZLLentz Jun 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs for this one are a whirlwind:

class typing.ContextManager(Generic[T_co])
A generic version of [contextlib.AbstractContextManager](https://docs.python.org/3/library/contextlib.html#contextlib.AbstractContextManager).

New in version 3.5.4.

New in version 3.6.0.

Deprecated since version 3.9: [contextlib.AbstractContextManager](https://docs.python.org/3/library/contextlib.html#contextlib.AbstractContextManager) now supports []

I think the cleanest thing to do is to use the 3.9 version and make sure the annotations future import is on

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backtracking: I think my existing setup is more correct than ContextManager. I think ContextManager is for saying "this function returns a context manager that yields a LineProfiler", while I'm trying to say "this context manager yields a LineProfiler".

I'm asserting this based on how much less helpful VSCode started being with the output once I swapped it over, claiming that my "profiler" instance in the tests was type context manager.

Copy link
Copy Markdown
Contributor

@klauer klauer Jun 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh... oh my, what a mess - I should have started at the 3 docs instead of the 3.8 docs. I'm glad you double-checked.

Good call on the annotations future approach - that is clean to me 👍

GitHub didn't show me your latest comment while I typed the above - I see now and I also learned something. Thanks!

Copy link
Copy Markdown
Contributor

@tangkong tangkong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I'm learning a lot about python today

@ZLLentz ZLLentz merged commit e6e0aea into pcdshub:master Jun 17, 2022
@ZLLentz ZLLentz deleted the fix-profiler-static-cls branch June 17, 2022 00:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Profiler does not include static methods Profiler should include class methods as well

3 participants