Skip to content

Use return instead of twisted.defer.returnValue#2955

Merged
johannaengland merged 2 commits intoUninett:masterfrom
johannaengland:deprecation/replace-defer-returnvalue-with-return
Apr 25, 2025
Merged

Use return instead of twisted.defer.returnValue#2955
johannaengland merged 2 commits intoUninett:masterfrom
johannaengland:deprecation/replace-defer-returnvalue-with-return

Conversation

@johannaengland
Copy link
Copy Markdown
Contributor

In the last week when running the tests I got a lot of a similar warning:

DeprecationWarning: twisted.internet.defer.returnValue was deprecated in Twisted 24.7.0; please use standard return statement instead
    defer.returnValue(serial)

I replaced all occurrences of defer.returnValue with return.
Reference: https://github.com/twisted/twisted/blob/HEAD/NEWS.rst#deprecations-and-removals, twisted/twisted#9930

@codecov
Copy link
Copy Markdown

codecov bot commented Aug 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 0.00%. Comparing base (70d03b7) to head (8450d79).
Report is 3 commits behind head on master.

Additional details and impacted files
@@      Coverage Diff       @@
##   master   #2955   +/-   ##
==============================
==============================

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Member

@lunkwill42 lunkwill42 left a comment

Choose a reason for hiding this comment

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

While I'm really glad to see Twisted embrace newer Python constructs by deprecating their old kludges (that, in all fairness, were implemented to enable these kinds of programming paradigms under older Pythons), I think this approach should not be the immediate one.

Although the deprecation warnings do not actually break anything in NAV, they will be quite annoying, and so we have to make a decision about locking the Twisted version requirement.

Currently, NAV claims to work with at least version 23.8. If we make these changes, NAV will no longer work with Twisted 23, and we must upgrade to Twisted 24. It's either that, or lock to Twisted 23 in stable versions and make this change later.

I also think we should investigate the other changes mentioned in relation to this: The fact that the inlineCallbacks decorator might change or become deprecated in favor or Python's built-in co-routines. This would affect a lot of the ipdevpoll codebase as well.

There's also the slightly unrelated fact that a lot of ipdevpoll code was started even before inlineCallbacks appeared, and as such are purely callback-oriented. These parts of the codebase might stand to be refactored as well.

My dream is that we eventually will migrate the codebase to asyncio - the only reason we are sticking with Twisted is because of the inherited twistedsnmp interface of pynetsnmp. I believe it is quite possible to have Twisted and asyncio to co-exist these days. If the codebase could be mostly asyncio-oriented, with adaptations to keep pynetsnmp, that would be nice. There's also the option to rewrite pynetsnmp-2 to asyncio, since we've already forked it.

I.e. I want to keep this, but not merge it just yet.

@lunkwill42 lunkwill42 added blocked discussion Requires developer feedback/discussion before implementation labels Aug 20, 2024
@lunkwill42
Copy link
Copy Markdown
Member

Link for future reference: twisted/twisted#12239

lunkwill42 added a commit that referenced this pull request Oct 3, 2024
Twisted 24 introduces many deprecation warnings, and we want to avoid
them.  PR #2955 introduces a fix, of sorts, but this would require
Twisted 24 and above, so it has been put on ice for now.
@lunkwill42 lunkwill42 force-pushed the deprecation/replace-defer-returnvalue-with-return branch from d959a80 to 8e573ea Compare April 7, 2025 08:45
@lunkwill42
Copy link
Copy Markdown
Member

I've rebased this on the latest master and added a commit to change NAV's requirement to Twisted>=24.7

@lunkwill42
Copy link
Copy Markdown
Member

The above mentioned Twisted PR that changes this behavior seems to suggest that there might be problems using addCallback() or addErrback() on the return values of inlineCallbacks-decorated functions that use plain return. We should verify whether this is a problem (I suspect our test coverage in this area is poor).

@lunkwill42
Copy link
Copy Markdown
Member

The above mentioned Twisted PR that changes this behavior seems to suggest that there might be problems using addCallback() or addErrback() on the return values of inlineCallbacks-decorated functions that use plain return. We should verify whether this is a problem (I suspect our test coverage in this area is poor).

The main PR description mentions this without detail, but delving into the documentation the PR changes, it seems this only applies to functions that are rewritten from using inlineCallbacks decorators to pure Python co-routines (i.e. converting the functions to async def).

This will be a problem for a different PR.

@lunkwill42 lunkwill42 added nonews No news fragment is necessary for this PR (e.g. refactoring, cleanups, workflow/development changes) and removed blocked discussion Requires developer feedback/discussion before implementation labels Apr 7, 2025
Copy link
Copy Markdown
Member

@lunkwill42 lunkwill42 left a comment

Choose a reason for hiding this comment

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

As mentioned, I rebased this onto the latest master. The only relevant change from the first iteration, I guess, was to the recently updated paloaltoarp.py plugin in ipdevpoll.

johannaengland and others added 2 commits April 24, 2025 15:10
returnValue has been deprecated in twisted 24.7.0
From Twisted 24.7, `twisted.internet.defer.returnValue()` has been
deprecated and can be replaced by using Python's built-in `return`.  We
have done so, so there is no going back.
@johannaengland johannaengland force-pushed the deprecation/replace-defer-returnvalue-with-return branch from 8e573ea to 8450d79 Compare April 24, 2025 13:11
@sonarqubecloud
Copy link
Copy Markdown

@johannaengland johannaengland merged commit 9f87798 into Uninett:master Apr 25, 2025
13 checks passed
@johannaengland johannaengland deleted the deprecation/replace-defer-returnvalue-with-return branch April 25, 2025 07:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deprecation nonews No news fragment is necessary for this PR (e.g. refactoring, cleanups, workflow/development changes)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants