Skip to content

Clarify lifespan vs on_startup/on_shutdown priority#2193

Merged
Kludex merged 12 commits intoKludex:masterfrom
stratosgear:patch-1
Jul 5, 2023
Merged

Clarify lifespan vs on_startup/on_shutdown priority#2193
Kludex merged 12 commits intoKludex:masterfrom
stratosgear:patch-1

Conversation

@stratosgear
Copy link
Contributor

As per discussion (#2192), I am trying to make it more clear that if both lifespan AND on_startup/on_shutdown are used, regardless of the subtle hint that both should NOT be used, then only lifespan would be used and on_startup/on_shutdown would silently be ignored.

As per discussion (Kludex#2192), I am trying to make it more clear that if both lifespan AND on_startup/on_shutdown are used, regardless of the subtle hint that both should NOT be used, then only lifespan would be used and  on_startup/on_shutdown would silently be ignored.
@Kludex
Copy link
Owner

Kludex commented Jun 23, 2023

I don't think this is what we meant on the discussion (at least not what I mean). 🤔

I mean to raise a warning if lifespan is used on Router if not provided from Starlette.

@stratosgear
Copy link
Contributor Author

Something like this?

@stratosgear stratosgear changed the title Clarify lifespan vs on_startuo/on_shutdown priority Clarify lifespan vs on_startup/on_shutdown priority Jun 24, 2023
@Kludex
Copy link
Owner

Kludex commented Jun 25, 2023

Yes. Are you able to create tests for it?

@stratosgear
Copy link
Contributor Author

Something like this? Note, locally some existing tests would still fail with:

+ venv/bin/mypy starlette tests
starlette/routing.py:638: error: Incompatible types in assignment (expression has type "Union[Callable[[Any], AbstractAsyncContextManager[None]], Callable[[Any], AbstractAsyncContextManager[Mapping[str, Any]]], None]", variable has type "Union[Callable[[Any], AbstractAsyncContextManager[None]], Callable[[Any], AbstractAsyncContextManager[Mapping[str, Any]]]]")  [assignment]
Found 1 error in 1 file (checked 67 source files)

But this has nothing to do with my patch!

@stratosgear
Copy link
Contributor Author

Just noticed that this is the same reason why the online tests fail too, but I have no idea how to fix those...

@Kludex
Copy link
Owner

Kludex commented Jun 26, 2023

Something like this? Note, locally some existing tests would still fail with:

+ venv/bin/mypy starlette tests
starlette/routing.py:638: error: Incompatible types in assignment (expression has type "Union[Callable[[Any], AbstractAsyncContextManager[None]], Callable[[Any], AbstractAsyncContextManager[Mapping[str, Any]]], None]", variable has type "Union[Callable[[Any], AbstractAsyncContextManager[None]], Callable[[Any], AbstractAsyncContextManager[Mapping[str, Any]]]]")  [assignment]
Found 1 error in 1 file (checked 67 source files)

But this has nothing to do with my patch!

It does. You added the conditional in a block of other elseifs.

@stratosgear
Copy link
Contributor Author

I am not sure I understand why it still fails. :(

I see your edit of moving my if inside the previous if (makes sense) but still it behaves very weird...

I'm not sure I can help anymore here... :(

@stratosgear
Copy link
Contributor Author

I now completely understand why so few projects have 100% test coverage. The amount of time I spend trying to make this trivial fix was close to 10 times more time in test authoring, rather than the actual code change itself (at least!!!).

I am not sure if you really persist and become more proficient how much more efficient this process ever becomes... So as much as I would like to also have 100% coverage in my projects I do not know if I would ever find the time to actually do it.

This is a task that I would not mind if some "testGPT" would ever take over! :)

@Kludex Kludex merged commit 0b3ea09 into Kludex:master Jul 5, 2023
@Kludex
Copy link
Owner

Kludex commented Jul 5, 2023

I now completely understand why so few projects have 100% test coverage. The amount of time I spend trying to make this trivial fix was close to 10 times more time in test authoring, rather than the actual code change itself (at least!!!).

I am not sure if you really persist and become more proficient how much more efficient this process ever becomes... So as much as I would like to also have 100% coverage in my projects I do not know if I would ever find the time to actually do it.

This is a task that I would not mind if some "testGPT" would ever take over! :)

It is worth it, and it actually saves a lot of time. :)

You should have asked for feedback if you were feeling frustrated. I believe the interpretation of the coverage report on your behalf was not accurate.

@stratosgear
Copy link
Contributor Author

You should have asked for feedback if you were feeling frustrated. I believe the interpretation of the coverage report on your behalf was not accurate.

I hope you mean the first time only, when I said "I'm not sure I can help anymore here... 😵‍💫 ", because after that I could not accept defeat and took a more serious look and finally changed the tests enough to pass the whole test suite. Give me some credit here! 😄

Kludex added a commit that referenced this pull request Jul 7, 2023
…own` (#2193)

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
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.

2 participants